Skip to content

theyworkforyou/shineyoureye-sinatra

Repository files navigation

Travis Status Coverage Status

Shine Your Eye (Sinatra)

This project is a lightweight parliamentary monitoring site for Nigeria. It uses EveryPolitician data, user-editable data (through prose.io), and CSV data. It doesn't use a database.

Approach

The approach of this project is similar to viewer-sinatra:

Non-technical users can use prose.io to add content to the prose repo. Then, whenever there is a change in that repo, the script runs, producing an updated version of the site in the static repo.

Running a static site vs a dynamic one has several advantages. Also, we benefit from GitHub's free hosting.

Data sources

This project uses data from several different sources:

  • The basic details of current Senators and members of the House of Representatives was generated from EveryPolitician. This EveryPolitician data is accessed using the everypolitician gem. The bin/everypolitician-to-csv script is used to convert the EveryPolitician data to CSV format. The data on Nigeria is sourced from:
  • Boundaries and geographical area information are from a MapIt instance: http://nigeria.mapit.mysociety.org/
    • Mappings between Federal Constituencies and Sentorial Districts and their parent states are stored in the responsitory. (n.b. these could be set in MapIt instead; in fact, the senatorial districts already have parent_area set to the appropriate state):
      • mapit/sen_to_sta_area_ids_mapping.csv
      • mapit/fed_to_sta_area_ids_mapping.csv
      • mapit/lga_to_sta_area_ids_mapping.csv
    • Mappings between EveryPolitician area IDs and MapIt area IDs are stored in the repository:
      • mapit/mapit_to_ep_area_ids_mapping_FED.csv
      • mapit/mapit_to_ep_area_ids_mapping_SEN.csv
      • mapit/mapit_to_ep_area_ids_mapping_LGA.csv
    • Mappings between the slugs used for places in the old Pombola-based ShineYourEye website and MapIt IDs are stored in the repository:
      • mapit/pombola_place_slugs_to_mapit.csv
  • Details of local governors are from a scraper hosted on Morph https://morph.io/everypolitician-scrapers/nigeria-state-governors
  • The images of politicians referenced by the site are served from GitHub pages:
    • https://github.com/theyworkforyou/shineyoureye-images
    • That repository caches, at various sizes, the images from EveryPolitician. The cache is generated by the multiple-thumbnail-sizes branch of image_cache: https://github.com/everypolitician/image_cache/tree/multiple-thumbnail-sizes

Development

If you want to contribute to this project, please read our contributing guidelines.

How to use this project

This is a Ruby project. You will need to tell your favourite Ruby version manager to set your local Ruby version to the one specified in the Gemfile file.

For example, if you are using rbenv:

  1. Install the right Ruby version. That would be the version specified at the beginning of the Gemfile. For example, if it was ruby '2.5.3', you would type:
rbenv install 2.5.3
rbenv rehash
  1. Then you would move to the root directory of this project and type:
rbenv local 2.5.3
ruby -v

You will also need to install the bundler gem, which will allow you to install the rest of the dependencies listed in the Gemfile file of this project.

gem install bundler
rbenv rehash

Folder structure

  • bin : scripts, like deploy scripts, etc.
  • lib : the codebase
  • lib/document: code to parse prose.io files (markdown with frontmatter)
  • lib/ep: code to parse EveryPolitician data
  • lib/helpers: mostly site-specific stuff
  • lib/mapit: code to parse Mapit data
  • lib/membership_csv: code to parse membership data coming from a CSV file, for example a scraper running in Morph
  • lib/page: presenters to extract all logic out of the views
  • mapit: CSV files that map MapIt Area IDs to other IDs
  • morph: CSV files produced by a scraper on morph.io
  • prose: where the shineyoureye-prose repository will be cloned. Contains user introduced content, like blog posts, events, etc.
  • public: static assets
  • public/stylesheets/sass: sass files automatically compiled into css
  • tests: all the tests
  • views: the erb templates to build the site

Running the app

Initialise the project

bundle install

Prepare data for the app

bin/prepare-data

This will copy the user-editable contents of the site (the blog posts and static pages generated using prose.io) into a prose directory.

Run the app

bundle exec rackup

And go to http://localhost:9292/

Tests and RuboCop

For the tests, some of the user-editable contents of the site are used as fixtures. So we have to use this data in a particular point of its history. We can do that by positioning the repo at a particular commit, using the same script we used before. For example, to use the contents as they looked like at commit ffc1fe0:

bin/prepare-data ffc1fe0

The right commit to use will be whichever the .travis.yml file is using.

After doing this, we can run the tests.

Run both the tests and RuboCop checks

bundle exec rake

Running just the RuboCop checks

bundle exec rake rubocop

Running just the tests

bundle  exec rake test

Run the tests from just one file

bundle exec rake test TEST='path/to/test/file'