diff options
| author | Alban Peignier | 2012-04-16 14:56:38 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2012-04-16 14:56:38 +0200 | 
| commit | cda5d74c245e03c194996a3cfe5221785474d12b (patch) | |
| tree | f43323e16d0d60c54e645db1ae1c63e1b4f611b1 | |
| parent | a3b6f1c459e409023a1ef531e4f6f8084731a8f9 (diff) | |
| download | chouette-core-cda5d74c245e03c194996a3cfe5221785474d12b.tar.bz2 | |
Manage help texts with a dedicated HelpController. Refs #12
| -rw-r--r-- | app/assets/javascripts/help.js.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/help.css.scss (renamed from doc/functional/stylesheets/help.scss) | 32 | ||||
| -rw-r--r-- | app/controllers/help_controller.rb | 13 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 7 | ||||
| -rw-r--r-- | app/helpers/help_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/help_page.rb | 46 | ||||
| -rw-r--r-- | app/views/help/companies.textile (renamed from doc/functional/companies.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/dataspaces.textile (renamed from doc/functional/dataspaces.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/index.textile (renamed from doc/functional/index.textile) | 2 | ||||
| -rw-r--r-- | app/views/help/introduction.textile (renamed from doc/functional/introduction.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/lines.textile (renamed from doc/functional/lines.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/networks.textile (renamed from doc/functional/networks.textile) | 2 | ||||
| -rw-r--r-- | app/views/help/normalisation.textile (renamed from doc/functional/normalisation.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/restapis.textile (renamed from doc/functional/restapis.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/show.html.erb | 3 | ||||
| -rw-r--r-- | app/views/help/stop_areas.textile (renamed from doc/functional/stop_areas.textile) | 0 | ||||
| -rw-r--r-- | app/views/help/timetables.textile (renamed from doc/functional/timetables.textile) | 0 | ||||
| -rw-r--r-- | app/views/layouts/_user_links.erb | 6 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 8 | ||||
| -rw-r--r-- | config/routes.rb | 2 | ||||
| -rw-r--r-- | spec/controllers/help_controller_spec.rb | 9 | ||||
| -rw-r--r-- | spec/helpers/help_helper_spec.rb | 15 | 
22 files changed, 128 insertions, 22 deletions
| diff --git a/app/assets/javascripts/help.js.coffee b/app/assets/javascripts/help.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/help.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/doc/functional/stylesheets/help.scss b/app/assets/stylesheets/help.css.scss index 1923a494e..ca68e15b5 100644 --- a/doc/functional/stylesheets/help.scss +++ b/app/assets/stylesheets/help.css.scss @@ -1,68 +1,70 @@ -#workspace h2 { +#workspace.help { +h2 {      font-size: 17px;  } -#workspace h3 { +h3 {      font-size: 15px;  } -#workspace h4 { +h4 {      font-weight: bold;      padding: 7px 0;  } -#workspace ul li { +ul li {      list-style: circle;      margin: 7px 0 7px 20px;  } -#workspace ol { +ol {      list-style: none;       margin: 7px 0 7px 20px;      padding: 0;      counter-reset: num;  } -#workspace ol li:before { +ol li:before {      content: counter(num) '. ';      counter-increment: num;  } -#workspace ol ol li:before { +ol ol li:before {      content: counters(num, '.') ' ';  } -#workspace em { +em {      font-style: italic;  } -#workspace strong { +strong {      font-weight: bold;  } -#workspace cite { +cite {    font-style: italic;  } -#workspace p.attr_data { +p.attr_data {    font-style: italic;    text-decoration: underline;  } -#workspace table { +table {      width: 100%;  } -#workspace table td { +table td {      padding: 3px 5px;      width: 30%;  } -#workspace dt { +dt {      font-style:italic;      margin: 5px 0;   } -#workspace dd { +dd {      padding-left: 10px;  } +} diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb new file mode 100644 index 000000000..92f96ebd7 --- /dev/null +++ b/app/controllers/help_controller.rb @@ -0,0 +1,13 @@ +class HelpController < ApplicationController + +  def show +    @page = HelpPage.find(slug) +  end + +  private + +  def slug +    params[:slug] or "index" +  end + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cf6486306..29951da87 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -4,5 +4,12 @@ module ApplicationHelper      @referential.present? and not @referential.new_record?    end +  def help_page? +    controller_name == "help" +  end + +  def help_path +    url_for(:controller => "help", :action => "show") + '/' +  end  end diff --git a/app/helpers/help_helper.rb b/app/helpers/help_helper.rb new file mode 100644 index 000000000..6a35490ac --- /dev/null +++ b/app/helpers/help_helper.rb @@ -0,0 +1,2 @@ +module HelpHelper +end diff --git a/app/models/help_page.rb b/app/models/help_page.rb new file mode 100644 index 000000000..1207c5198 --- /dev/null +++ b/app/models/help_page.rb @@ -0,0 +1,46 @@ +class HelpPage + +  attr_accessor :slug, :content, :data + +  def initialize(slug) +    @slug = slug +    @data = {}.with_indifferent_access +  end + +  def filename +    "#{Rails.root}/app/views/help/#{slug}.textile" +  end + +  def exists? +    File.exists? filename +  end + +  def load +    self.content = File.read(filename) +    self.data ||= {} + +    if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m +      self.content = $POSTMATCH +      self.data.merge! YAML.load($1) +    end +  end + +  def method_missing(method, *arguments) +    if arguments.empty? and data.has_key?(method) +      data[method] +    else +      super +    end +  end + +  def self.find(slug) +    new(slug).tap do |page| +      if page.exists? +        page.load +      else +        raise ActiveRecord::RecordNotFound  +      end +    end +  end + +end diff --git a/doc/functional/companies.textile b/app/views/help/companies.textile index c1db6f4d3..c1db6f4d3 100644 --- a/doc/functional/companies.textile +++ b/app/views/help/companies.textile diff --git a/doc/functional/dataspaces.textile b/app/views/help/dataspaces.textile index 536ea4173..536ea4173 100644 --- a/doc/functional/dataspaces.textile +++ b/app/views/help/dataspaces.textile diff --git a/doc/functional/index.textile b/app/views/help/index.textile index b34d4e0bc..64a4281e5 100644 --- a/doc/functional/index.textile +++ b/app/views/help/index.textile @@ -1,6 +1,6 @@  ---  layout: default -title: Présentation +title: Présentation  ---  Chouette v2 : itération 4 du 16/04/2012 diff --git a/doc/functional/introduction.textile b/app/views/help/introduction.textile index 71f954d53..71f954d53 100644 --- a/doc/functional/introduction.textile +++ b/app/views/help/introduction.textile diff --git a/doc/functional/lines.textile b/app/views/help/lines.textile index 9997c0d50..9997c0d50 100644 --- a/doc/functional/lines.textile +++ b/app/views/help/lines.textile diff --git a/doc/functional/networks.textile b/app/views/help/networks.textile index d9ef4d0b3..424808f48 100644 --- a/doc/functional/networks.textile +++ b/app/views/help/networks.textile @@ -1,6 +1,6 @@  ---  layout: default -title: Réseaux +title: Réseaux  ---  h3. Définition diff --git a/doc/functional/normalisation.textile b/app/views/help/normalisation.textile index 2790d5320..2790d5320 100644 --- a/doc/functional/normalisation.textile +++ b/app/views/help/normalisation.textile diff --git a/doc/functional/restapis.textile b/app/views/help/restapis.textile index ed4aaf3b4..ed4aaf3b4 100644 --- a/doc/functional/restapis.textile +++ b/app/views/help/restapis.textile diff --git a/app/views/help/show.html.erb b/app/views/help/show.html.erb new file mode 100644 index 000000000..b5c8506ee --- /dev/null +++ b/app/views/help/show.html.erb @@ -0,0 +1,3 @@ +<h2><%= @page.title %></h2> + +<%= textilize(@page.content).html_safe %> diff --git a/doc/functional/stop_areas.textile b/app/views/help/stop_areas.textile index f527798fe..f527798fe 100644 --- a/doc/functional/stop_areas.textile +++ b/app/views/help/stop_areas.textile diff --git a/doc/functional/timetables.textile b/app/views/help/timetables.textile index 57fe0d50b..57fe0d50b 100644 --- a/doc/functional/timetables.textile +++ b/app/views/help/timetables.textile diff --git a/app/views/layouts/_user_links.erb b/app/views/layouts/_user_links.erb index f82d4d7b4..ccbe17596 100644 --- a/app/views/layouts/_user_links.erb +++ b/app/views/layouts/_user_links.erb @@ -9,11 +9,11 @@    <% end %>    <li> | </li> -  <li class="<%= language_class("fr") %>"><%= link_to_language :fr %></li> -  <li class="<%= language_class("en") %>"><%= link_to_language :en %></li> +  <li class="<%= language_class('fr') %>"><%= link_to_language :fr %></li> +  <li class="<%= language_class('en') %>"><%= link_to_language :en %></li>    <li>    <li> | </li>  -  <%= link_to "/help/index" do %> +  <%= link_to help_path do %>      <span class="help"><%= t('layouts.help') %></span>    <% end %>    </li> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index ceafd8944..f75b138fe 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -21,6 +21,8 @@          <div class="title">             <% if selected_referential? %>              <h1><%= @referential.name %></h1> +          <% elsif help_page? %> +            <h1>Documentation</h1>            <% end %>          </div>          <div class="interaction"> @@ -29,8 +31,10 @@        </div>        <div class="tabs">          <ul class="main"> -          <% unless selected_referential? %> -            <li><%= tab_link_to Referential, referentials_path %></li> +          <% if help_page? %> +            <li><%= link_to "Aide", help_path, :class => "current" %></li> +          <% elsif ! selected_referential? %> +            <li><%= tab_link_to Referential, referentials_path, :class => "current" %></li>            <% else %>              <li><%= link_to t("layouts.tabs.dashboard"), referential_path(@referential), :class => ("current" if current_page?(referential_path(@referential))) %></li>              <li><%= tab_link_to Chouette::Network, referential_networks_path(@referential) %></li> diff --git a/config/routes.rb b/config/routes.rb index c0e652ca7..df64353d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,8 @@ ChouetteIhm::Application.routes.draw do      resources :companies, :stop_areas, :time_tables    end  +  match '/help/(*slug)' => 'help#show' +    # Sample resource route with options:    #   resources :products do    #     member do diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb new file mode 100644 index 000000000..2ad167012 --- /dev/null +++ b/spec/controllers/help_controller_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe HelpController do + +  it "should render static files from app/views/help" do +    get "/" +  end + +end diff --git a/spec/helpers/help_helper_spec.rb b/spec/helpers/help_helper_spec.rb new file mode 100644 index 000000000..29709b960 --- /dev/null +++ b/spec/helpers/help_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the HelpHelper. For example: +# +# describe HelpHelper do +#   describe "string concat" do +#     it "concats two strings with spaces" do +#       helper.concat_strings("this","that").should == "this that" +#     end +#   end +# end +describe HelpHelper do +  pending "add some examples to (or delete) #{__FILE__}" +end | 
