diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 1271129..4844674 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -5,5 +5,7 @@ @import 'neat'; @import 'global'; +@import 'tables'; @import 'navigation'; @import 'home'; +@import 'volumes'; diff --git a/app/assets/stylesheets/global.css.scss b/app/assets/stylesheets/global.css.scss index 36901c4..d6ad468 100644 --- a/app/assets/stylesheets/global.css.scss +++ b/app/assets/stylesheets/global.css.scss @@ -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%; } diff --git a/app/assets/stylesheets/navigation.css.scss b/app/assets/stylesheets/navigation.css.scss index a4e6fc0..9cea955 100644 --- a/app/assets/stylesheets/navigation.css.scss +++ b/app/assets/stylesheets/navigation.css.scss @@ -18,7 +18,7 @@ nav { font-variant: small-caps; &:hover { - color: #2C98C8; + color: $blue; } } diff --git a/app/assets/stylesheets/tables.css.scss b/app/assets/stylesheets/tables.css.scss new file mode 100644 index 0000000..0241f06 --- /dev/null +++ b/app/assets/stylesheets/tables.css.scss @@ -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%); + } +} diff --git a/app/assets/stylesheets/volumes.css.scss b/app/assets/stylesheets/volumes.css.scss new file mode 100644 index 0000000..8932ecf --- /dev/null +++ b/app/assets/stylesheets/volumes.css.scss @@ -0,0 +1,5 @@ +table { + margin-top: 30px; + margin-left: auto; + margin-right: auto; +} diff --git a/app/controllers/volumes_controller.rb b/app/controllers/volumes_controller.rb new file mode 100644 index 0000000..adb90ec --- /dev/null +++ b/app/controllers/volumes_controller.rb @@ -0,0 +1,7 @@ +class VolumesController < ApplicationController + respond_to :html + + def index + @volumes = Volume.sort_by_number_desc.decorate + end +end diff --git a/app/decorators/volume_decorator.rb b/app/decorators/volume_decorator.rb new file mode 100644 index 0000000..0891224 --- /dev/null +++ b/app/decorators/volume_decorator.rb @@ -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 diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 654a76a..3fb614d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -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', '#' diff --git a/app/views/volumes/index.html.haml b/app/views/volumes/index.html.haml new file mode 100644 index 0000000..c6e6a05 --- /dev/null +++ b/app/views/volumes/index.html.haml @@ -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 diff --git a/config/application.rb b/config/application.rb index 012f4eb..6cf1628 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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. diff --git a/config/initializers/draper.rb b/config/initializers/draper.rb index e985df3..dacd478 100644 --- a/config/initializers/draper.rb +++ b/config/initializers/draper.rb @@ -1 +1,2 @@ Draper::CollectionDecorator.delegate :reorder, :page, :current_page, :total_pages, :limit_value, :total_count, :num_pages +Draper::Decorator.delegate :id, :to_key diff --git a/config/locales/en.yml b/config/locales/en.yml index 80d924b..f0ecf99 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 1f5cce8..5c2ae76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ ActiveAdmin.routes(self) resources :articles + resources :volumes get '/', controller: 'high_voltage/pages', action: :show, id: 'home' end diff --git a/lib/roman_numerals.rb b/lib/roman_numerals.rb new file mode 100644 index 0000000..24f6729 --- /dev/null +++ b/lib/roman_numerals.rb @@ -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 diff --git a/spec/features/volumes_spec.rb b/spec/features/volumes_spec.rb new file mode 100644 index 0000000..102a987 --- /dev/null +++ b/spec/features/volumes_spec.rb @@ -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