Skip to content

Commit

Permalink
Merge PR#48.
Browse files Browse the repository at this point in the history
  • Loading branch information
monfresh committed Aug 14, 2014
2 parents fe1e094 + ec30b65 commit 487bc95
Show file tree
Hide file tree
Showing 101 changed files with 3,753 additions and 1,193 deletions.
64 changes: 64 additions & 0 deletions INSTALL.md
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
69 changes: 16 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,32 @@

[SMC-Connect](http://www.smc-connect.org) is a Ruby on Rails app that makes it easy to find human services, farmers' markets, and other community organizations in San Mateo County, California. The website is powered by the [Ohana API](http://ohanapi.org) platform.

In San Mateo County, there are three Ohana apps: SMC-Connect, the [San Mateo County API](https://github.com/smcgov/ohana-api-smc) (that feeds the data to SMC-Connect), and the [admin interface](https://github.com/smcgov/SMC-Connect-Admin) that allows people to update the data.
This project was developed by [Code for America's 2013 San Mateo County, CA,](http://codeforamerica.org/2013-partners/san-mateo-county/) fellowship team: [@monfresh](https://github.com/monfresh), [@spara](https://github.com/spara), and [@anselmbradford](https://github.com/anselmbradford). Continued development of this project can be found in [Ohana Web Search](https://github.com/codeforamerica/ohana-web-search).

In San Mateo County, there are three Ohana apps: [SMC-Connect](http://smc-connect.org), the [San Mateo County API](https://github.com/smcgov/ohana-api-smc) (that feeds the data to SMC-Connect), and the [admin interface](https://github.com/smcgov/SMC-Connect-Admin) that allows people to update the data.

## Demo
You can see a running version of the application at
[http://ohana-web-search-demo.herokuapp.com/](http://ohana-web-search-demo.herokuapp.com/).
[http://smc-connect.org](http://smc-connect.org).

## Stack Overview

* Ruby version 2.1.1
* Rails version 4.0.4
* Template Engines: ERB and HAML
* Testing Frameworks: RSpec, Capybara and capybara-webkit


## Installation
Please note that the instructions below have only been tested on OS X. If you are running another operating system and run into any issues, feel free to update this README, or open an issue if you are unable to resolve installation issues.

###Prerequisites

#### Git, Ruby 2.1+, Rails 4+ (+ Homebrew on OS X)
**OS X**: [Set up a dev environment on OS X with Homebrew, Git, RVM, Ruby, and Rails](http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/)

**Windows**: Try [RailsInstaller](http://railsinstaller.org), along with some of these [tutorials](https://www.google.com/search?q=install+rails+on+windows) if you get stuck.

**Linux**:

* [RVM](http://rvm.io) is great, and this project uses it, but in any case, try to use the same ruby version as listed in the .ruby-version file. If you install it, it'll take care of making sure you have the right ruby, and let you focus on contributing to the app.
* You need a Javascript runtime. We recommend Node.JS (if you have a good reason not to use it, [there are other options](https://github.com/sstephenson/execjs)). On Ubuntu, it's as simple as <code>sudo apt-get install nodejs</code>. On others, [check the official instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager).

#### PhantomJS
[Installation instructions](https://github.com/jonleighton/poltergeist#installing-phantomjs) for Mac, Linux, and Windows.

### Clone the app on your local machine:

git clone https://github.com/smcgov/SMC-Connect.git smc-connect
cd smc-connect

### Install the dependencies:

bundle

### Set up the environment variables
Inside the `config` folder, you will find a file named `application.example.yml`. Rename it to `application.yml` and double check that it is in your `.gitignore` file (it should be by default).

By default, the app is configured to point to the demo API at `http://ohanapi.herokuapp.com/api`. To point to your own instance of Ohana API, change the value of `OHANA_API_ENDPOINT` in your `application.yml`.

Note that if you had previously installed this repo locally, you will need to update your `application.yml` to point to the new demo API, or any v2.0.0 Ohana API.

### Run the app
Start the app locally on port 4000 using Unicorn:
* Testing Frameworks: RSpec, Capybara and poltergeist

unicorn -p 4000

Ohana SMC should now be running at [http://lvh.me:4000](http://lvh.me:4000)
## Local Installation

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. For example, if you're also running the Ohana API locally (which uses port 8080 by default), you wouldn't be able to run Ohana Web Search with the simple `unicorn` command, because it would also default to port 8080. By specifying a different port number, you can run both servers at the same time.
Follow the instructions in [INSTALL.md][install].

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).
[install]: https://github.com/smcgov/SMC-Connect/blob/master/INSTALL.md

### Adjusting the number of results per page
The Ohana API now supports the ability to set the number of results you want returned per page via the `per_page` parameter (with a maximum of 100). So, if you want to test the layout of the results page with a certain number of results, just add something like `&per_page=5` to the end of the URL.
## Adjusting the number of results per page
The Ohana API now supports the ability to set the number of results you want returned per page via the `per_page` parameter (with a maximum value of 100). If you want to view a different number of results per page, add `&per_page=1` or similar to the end of the URL.

### Test the app
## Running the tests
To test locally, you can run tests with this simple command:

rspec
Expand All @@ -80,21 +43,21 @@ The `--color` option allows you to see passing tests in green and failing ones i

Parameters for the `--format` option are: `progress` (default - shows a series of dots), `documentation`, `html`, or `textmate`. [More information can be found on the RSpec website](https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/configuration/read-command-line-configuration-options-from-files).

For faster tests:
For faster tests (optional):

gem install zeus
zeus start #in a separate Terminal window or tab
zeus rspec spec

Read more about [Zeus](https://github.com/burke/zeus).

To see the actual tests, browse through the [spec](https://github.com/codeforamerica/ohana-web-search/tree/master/spec) directory.
To see the actual tests, browse through the [spec](https://github.com/smcgov/SMC-Connect/tree/master/spec) directory.

## Contributing
We'd love to get your help developing this project! Take a look at the [Contribution Document](https://github.com/codeforamerica/ohana-web-search/blob/master/CONTRIBUTING.md) to see how you can make a difference.
We'd love to get your help developing this project! Take a look at the [Contribution Document](https://github.com/smcgov/SMC-Connect/blob/master/CONTRIBUTING.md) to see how you can make a difference.

## Supported Ruby Version
This library aims to support and is [tested against](http://travis-ci.org/codeforamerica/ohana-web-search) Ruby version 2.1.1.
This library aims to support and is [tested against](http://travis-ci.org/smcgov/SMC-Connect) Ruby version 2.1.1.

If something doesn't work on this version, it should be considered a bug.

Expand All @@ -103,4 +66,4 @@ This library may inadvertently work (or seem to work) on other Ruby implementati
If you would like this library to support another Ruby version, you may volunteer to be a maintainer. Being a maintainer entails making sure all tests run and pass on that implementation. When something breaks on your implementation, you will be personally responsible for providing patches in a timely fashion. If critical issues for a particular implementation exist at the time of a major release, support for that Ruby version may be dropped.

## Copyright
Copyright (c) 2013 Code for America. See [LICENSE](https://github.com/codeforamerica/ohana-web-search/blob/master/LICENSE.md) for details.
Copyright (c) 2013 Code for America. See [LICENSE](https://github.com/smcgov/SMC-Connect/blob/master/LICENSE.md) for details.
File renamed without changes
2 changes: 1 addition & 1 deletion app/assets/javascripts/app/feedback-form-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['util/util','jquery'],function(util,$) {
{
var agent = '\nUser agent: ' + navigator.userAgent;

var csrfToken = $("meta[name='csrf-token']").attr("content");
var csrfToken = $('meta[name="csrf-token"]').attr('content');

var transmission = {
message: _commentInput.value,
Expand Down
22 changes: 17 additions & 5 deletions app/assets/javascripts/detail/detail-init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
require(['detail/detail-map-manager','detail/character-limiter','detail/term-popup-manager','search/header-manager'],function (map,cl,tpm,header) {
require([
'detail/detail-map-manager',
'detail/character-limiter',
'detail/term-popup-manager',
'search/header-manager'
], function (map, cl, tpm, header) {
'use strict';

map.init();
Expand All @@ -8,18 +13,25 @@ require(['detail/detail-map-manager','detail/character-limiter','detail/term-pop

}, function (err) {
'use strict';
//The error callback
//The err object has a list of modules that failed
//The error callback.
//The err object has a list of modules that failed.
var failedId = err.requireModules && err.requireModules[0];
requirejs.undef(failedId);

console.log("RequireJS threw an Error:",failedId,err.requireType);

// initialize no map loaded state
require(['detail/no-detail-map-manager','detail/character-limiter','detail/term-popup-manager','search/header-manager'], function (map,cl,tpm,header) {
// Initialize no map loaded state.
require([
'detail/no-detail-map-manager',
'detail/character-limiter',
'detail/term-popup-manager',
'search/header-manager'
], function (map, cl, tpm, header) {

map.init();
cl.init();
tpm.init();
header.init();

});
});
11 changes: 5 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module ApplicationHelper

# Handles formatting of the page title by appending site name to end
# of a particular page's title.
# Appends the site title to the end of the page title.
# The site title is defined in config/settings.yml.
# @param page_title [String] the page title from a particular view.
def title(page_title)
default = "SMC-Connect"
site_title = SETTINGS[:site_title]
if page_title.present?
content_for :title, "#{page_title.to_str} | #{default}"
content_for :title, "#{page_title.to_s} | #{site_title}"
else
content_for :title, default
content_for :title, site_title
end
end

Expand Down Expand Up @@ -226,5 +226,4 @@ def taxonomy_terms
]
}
end

end
61 changes: 61 additions & 0 deletions app/helpers/homepage_links_helper.rb
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
73 changes: 73 additions & 0 deletions app/helpers/info_box_helper.rb
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
Loading

0 comments on commit 487bc95

Please sign in to comment.