Skip to content

Commit

Permalink
Add volumes page
Browse files Browse the repository at this point in the history
  • Loading branch information
mwean committed Sep 13, 2013
1 parent d38a364 commit af01c02
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
@import 'neat';

@import 'global';
@import 'tables';
@import 'navigation';
@import 'home';
@import 'volumes';
2 changes: 2 additions & 0 deletions app/assets/stylesheets/global.css.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@import url(http://fonts.googleapis.com/css?family=Raleway);
@import url(http://fonts.googleapis.com/css?family=Open%20Sans);

$blue: #2C98C8;

html {
height: 100%;
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/navigation.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nav {
font-variant: small-caps;

&:hover {
color: #2C98C8;
color: $blue;
}
}

Expand Down
29 changes: 29 additions & 0 deletions app/assets/stylesheets/tables.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
table {
max-width: 800px;
min-width: 450px;

.center {
text-align: center;
}
}

th {
border-bottom: 1px solid #bbb;
}

td {
padding: 8px;
line-height: 1;

&:not(.center) {
padding-left: 20px;
}
}

tbody tr {
border-bottom: 1px solid #ddd;

&:hover {
background-color: tint($blue, 30%);
}
}
5 changes: 5 additions & 0 deletions app/assets/stylesheets/volumes.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
table {
margin-top: 30px;
margin-left: auto;
margin-right: auto;
}
7 changes: 7 additions & 0 deletions app/controllers/volumes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class VolumesController < ApplicationController
respond_to :html

def index
@volumes = Volume.sort_by_number_desc.decorate
end
end
11 changes: 11 additions & 0 deletions app/decorators/volume_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class VolumeDecorator < ApplicationDecorator
delegate :number, :year, :isbn

def name
"Nikephoros #{roman_numeral}"
end

def roman_numeral
RomanNumerals.to_roman(number.to_i)
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
%h1= link_to 'Nikephoros', '/'
.pages
%ul
%li= link_to 'Volumes', '#'
%li= link_to 'Volumes', volumes_path
%li= link_to 'Authors', '#'
%li= link_to 'Articles', '#'

Expand Down
11 changes: 11 additions & 0 deletions app/views/volumes/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%table
%thead
%tr
%th= t('volume')
%th= t('year')
%th= t('isbn')
%tbody
= content_tag_for(:tr, @volumes) do |volume|
%td= volume.name
%td{ class: :center }= volume.year
%td= volume.isbn
19 changes: 10 additions & 9 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ module Nikephoros
class Application < Rails::Application
config.active_record.default_timezone = :utc

config.generators do |generate|
generate.helper false
generate.javascript_engine false
generate.request_specs false
generate.routing_specs false
generate.stylesheets false
generate.test_framework :rspec
generate.view_specs false
end
config.generators do |generate|
generate.helper false
generate.javascript_engine false
generate.request_specs false
generate.routing_specs false
generate.stylesheets false
generate.test_framework :rspec
generate.view_specs false
end

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.autoload_paths << File.join(config.root, 'lib')

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
Expand Down
1 change: 1 addition & 0 deletions config/initializers/draper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Draper::CollectionDecorator.delegate :reorder, :page, :current_page, :total_pages, :limit_value, :total_count, :num_pages
Draper::Decorator.delegate :id, :to_key
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ en:
default: '%a, %b %-d, %Y at %r'
date: '%b %-d, %Y'
short: '%B %d'

volume: Volume
year: Year
isbn: ISBN
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ActiveAdmin.routes(self)

resources :articles
resources :volumes

get '/', controller: 'high_voltage/pages', action: :show, id: 'home'
end
40 changes: 40 additions & 0 deletions lib/roman_numerals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class RomanNumerals
CONVERSIONS = {
0 => '',
1 => 'I',
2 => 'II',
3 => 'III',
4 => 'IV',
5 => 'V',
6 => 'VI',
7 => 'VII',
8 => 'VIII',
9 => 'IX',
10 => 'X',
20 => 'XX',
30 => 'XXX',
40 => 'XL',
50 => 'L',
60 => 'LX',
70 => 'LXX',
80 => 'LXXX',
90 => 'XC',
100 => 'C',
200 => 'CC',
300 => 'CCC',
400 => 'CD',
500 => 'D'
}

def self.to_roman(num)
str = ''

str << CONVERSIONS[convert_for_power(num, 100)]
str << CONVERSIONS[convert_for_power(num, 10)]
str << CONVERSIONS[convert_for_power(num, 1)]
end

def self.convert_for_power(num, power)
((num / power) % 10) * power
end
end
13 changes: 13 additions & 0 deletions spec/features/volumes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'spec_helper'

feature 'visiting the volumes page' do
scenario 'user sees a list of volumes' do
volume = FactoryGirl.create(:volume).decorate

visit volumes_path

expect(page).to have_css('td', text: volume.roman_numeral)
expect(page).to have_css('td', text: volume.year)
expect(page).to have_css('td', text: volume.isbn)
end
end

0 comments on commit af01c02

Please sign in to comment.