forked from codeforamerica/ohana-web-search
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
101 changed files
with
3,753 additions
and
1,193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Running SMC-Connect on your computer | ||
|
||
## Install Prerequisites | ||
|
||
Before you can run SMC-Connect, you'll need to have the following software | ||
packages installed on your computer: Git, Ruby 2.1+, RVM, and PhantomJS. | ||
If you're on a Linux machine, you'll also need Node.js. | ||
|
||
If you already have all of the prerequisites installed, you can go straight | ||
to the [Installation](#install-smc-connect). Otherwise, you'll need to | ||
install the following tools manually: | ||
|
||
- [Build tools][build-tools] | ||
- [Ruby with RVM][ruby] | ||
- [PhantomJS][phantomjs] (only used for running the tests) | ||
- [Node.js][node] (Linux only) | ||
|
||
[build-tools]: https://github.com/codeforamerica/howto/blob/master/Build-Tools.md | ||
[ruby]: https://github.com/codeforamerica/howto/blob/master/Ruby.md | ||
[phantomjs]: https://github.com/jonleighton/poltergeist#installing-phantomjs | ||
[node]: https://github.com/codeforamerica/howto/blob/master/Node.js.md | ||
|
||
|
||
## Install SMC-Connect | ||
|
||
### Fork and clone | ||
|
||
[Fork this repository to your GitHub account][fork]. | ||
|
||
Clone it on your computer and navigate to the project's directory: | ||
|
||
git clone https://github.com/<your GitHub username>/smc-connect.git && cd smc-connect | ||
|
||
[fork]: http://help.github.com/fork-a-repo/ | ||
|
||
### Install the dependencies: | ||
|
||
bundle | ||
|
||
### Set up the environment variables & customizable settings | ||
|
||
Inside the `config` folder, you will find a file named `application.example.yml`. | ||
Copy its contents to a new file called `application.yml`. | ||
|
||
By default, the app is configured to point to the San Mateo County, CA, API at | ||
`http://ohanapi.herokuapp.com/api`. | ||
|
||
Inside the `config` folder, you will also find a file called `settings.yml`. | ||
In that file, there are many settings you can customize. Please read through | ||
the instructions in that file carefully. By default the settings are configured | ||
for use with http://smc-connect.org, but can be customized if needed. | ||
|
||
### Run the app | ||
Start the app locally on port 4000: | ||
|
||
rails s -p 4000 | ||
|
||
SMC-Connect should now be running at [http://lvh.me:4000](http://lvh.me:4000) | ||
|
||
The `-p` option allows you to specify which port you want to run the server on. This is useful when running other servers at the same time. | ||
|
||
Please make sure you are using `lvh.me` instead of `localhost` to be able to test the translation feature. Read more about [lvh.me](http://matthewhutchinson.net/2011/1/10/configuring-subdomains-in-development-with-lvhme). | ||
|
||
[admin]: https://github.com/smcgov/SMC-Connect-Admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module HomepageLinksHelper | ||
# Hash representing headers and link text in the "general" category | ||
# of links displayed on the homepage, as defined in config/settings.yml. | ||
# | ||
# @return [Hash] Key: String header, Value: Array of link texts. | ||
def general_links | ||
SETTINGS.try(:[], :homepage_links).try(:[], 'general') | ||
end | ||
|
||
# Hash representing headers and link text in the "emergency" category | ||
# of links displayed on the homepage, as defined in config/settings.yml. | ||
# | ||
# @return [Hash] Key: String header, Value: Array of link texts. | ||
def emergency_links | ||
SETTINGS.try(:[], :homepage_links).try(:[], 'emergency') | ||
end | ||
|
||
# If the link text contains words separated by a slash, or if it contains | ||
# words enclosed in parentheses, it will only return the part of the String | ||
# that comes before the slash or the parentheses. | ||
# | ||
# Example: if "SNAP/Food Stamps" or "SNAP (Food Stamps)" is passed in, | ||
# it will return "SNAP" in both cases. | ||
# | ||
# @param link_text [String] A link text from the bottom half of homepage. | ||
# @return [String] | ||
def keyword_from_link_text(link_text) | ||
['/', '('].each do |char| | ||
link_text = link_text.split(char).first.strip if link_text.include?(char) | ||
end | ||
link_text | ||
end | ||
|
||
# Outputs HTML that displays the headers and link text on the bottom half | ||
# of the homepage. Called in app/views/home/_homepage_links.html.haml. | ||
# | ||
# @param link_group [Hash] Key: String header, Value: Array of link texts. | ||
# @return [HTML] | ||
def display_homepage_links(link_group) | ||
header = link_group.first | ||
links = link_group.second | ||
|
||
content_tag(:li) do | ||
concat(header) | ||
concat(content_tag(:ul) do | ||
links.each do |link_text| | ||
keyword = keyword_from_link_text(link_text) | ||
concat(content_tag(:li) do | ||
link_to( | ||
link_text, | ||
"/organizations?keyword=#{u keyword}", | ||
'class' => 'links-to-track', | ||
'data-ga-category' => 'Home_Categories', | ||
'data-ga-label' => "#{link_text}" | ||
) | ||
end) | ||
end | ||
end) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module InfoBoxHelper | ||
# Hash derived from info_box_terms in config/settings.yml. | ||
# The Hash keys represent the top-level terms, and the values | ||
# are Hashes representing the various attributes, such as synonyms, | ||
# title, description, and url. | ||
# | ||
# Here is an example Hash that would be returned: | ||
# { "wic" => { | ||
# "synonyms" => ["women, infants, and children", "wic"], | ||
# "title" => "Women, Infants, and Children", | ||
# "description" => "Women, Infants, and Children (WIC) provides...", | ||
# "url" => "http://www.fns.usda.gov/wic" | ||
# }, | ||
# "sfmnp" => { | ||
# "synonyms" => ["senior farmers' market nutrition program"], | ||
# "title" => "Senior Farmers' Market Nutrition Program", | ||
# "description" => "Senior Farmers' Market Nutrition Program (SFMNP)...", | ||
# "url" => "http://www.fns.usda.gov/sfmnp" | ||
# } | ||
# } | ||
# | ||
# @return [Hash] | ||
def info_box_hash | ||
SETTINGS.try(:[], :info_box_terms) | ||
end | ||
|
||
# Returns an array of all the synonyms from the info_box_hash. | ||
# | ||
# @return [Array] | ||
def synonyms | ||
info_box_hash.values.map { |hash| hash['synonyms'] }.flatten | ||
end | ||
|
||
# If the search keyword matches a synonym in the info_box_hash, | ||
# return the top-level key that corresponds to that synonym. | ||
# | ||
# @return [String] | ||
def info_box_key_corresponding_to_keyword | ||
keyword = params[:keyword].try(:downcase) | ||
if synonyms.include?(keyword) | ||
info_box_hash.find { |_, hash| hash['synonyms'].include? keyword }.first | ||
end | ||
end | ||
|
||
# @return [HTML] | ||
# Returns an HTML description list with the info box's title, | ||
# description, and a "More info..." link to its URL if it has one defined. | ||
def render_html_for_generic_info_box(info_box) | ||
content_tag :dl do | ||
concat(content_tag :dt, info_box['title']) | ||
concat(content_tag :dd, info_box['description']) | ||
if info_box['url'].present? | ||
concat(content_tag(:p) do | ||
link_to('More info...', info_box['url'], target: '_blank') | ||
end) | ||
end | ||
end | ||
end | ||
|
||
# @return [HTML] | ||
# If the info box has a "custom" key, render the partial that the | ||
# "custom" key points to. Otherwise, render the default description list | ||
# template defined in the method above. | ||
def render_info_box(info_box_key) | ||
info_box = info_box_hash[info_box_key] | ||
|
||
if info_box['custom'].present? | ||
render info_box['custom'] | ||
else | ||
render_html_for_generic_info_box(info_box) | ||
end | ||
end | ||
end |
Oops, something went wrong.