From 15ac566ecec8cffaa3829fa6fc153849f2c53a60 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 20 Mar 2015 16:32:58 +0100 Subject: [PATCH] Add help page for Foodsoft variables --- config/locales/en.yml | 5 +++++ lib/foodsoft/expansion_variables.rb | 2 +- plugins/wiki/app/controllers/pages_controller.rb | 15 +++++++++++++++ plugins/wiki/app/views/pages/_form.html.haml | 1 + plugins/wiki/app/views/pages/variables.html.haml | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 plugins/wiki/app/views/pages/variables.html.haml diff --git a/config/locales/en.yml b/config/locales/en.yml index 1030dcd3..4b093b98 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1386,6 +1386,11 @@ en: title: Title update: notice: Page was updated + variables: + title: Foodsoft variables + description: Variables return information from somewhere else. When you use the variable, it will be replaced by its value when displayed. Foodsoft has a number of pre-defined variables, such as the name and address of your foodcoop, the software version, and the number of members and suppliers. See the table below for all variables. You can use these in wiki pages as well as in the footer (from the configuration screen). + variable: Variable + value: Current value version: author: 'Author: %{user}' date_format: "%a, %d-%m-%Y, %H:%M" diff --git a/lib/foodsoft/expansion_variables.rb b/lib/foodsoft/expansion_variables.rb index ad00c1b7..224d0170 100644 --- a/lib/foodsoft/expansion_variables.rb +++ b/lib/foodsoft/expansion_variables.rb @@ -40,7 +40,7 @@ module Foodsoft 'supplier_count' => ->{ Supplier.undeleted.count }, 'active_supplier_count' => ->{ active_supplier_count }, 'active_suppliers' => ->{ active_suppliers }, - 'first_order_date' => ->{ I18n.l Order.first.created_at.to_date } + 'first_order_date' => ->{ I18n.l Order.first.try{|o| o.starts.to_date} } } # Return expanded variable diff --git a/plugins/wiki/app/controllers/pages_controller.rb b/plugins/wiki/app/controllers/pages_controller.rb index ab6b5426..4abbd265 100644 --- a/plugins/wiki/app/controllers/pages_controller.rb +++ b/plugins/wiki/app/controllers/pages_controller.rb @@ -1,6 +1,7 @@ # encoding: utf-8 class PagesController < ApplicationController before_filter -> { require_plugin_enabled FoodsoftWiki } + before_filter :catch_special_pages, only: [:show, :new] skip_before_filter :authenticate, :only => :all before_filter :only => :all do @@ -140,4 +141,18 @@ class PagesController < ApplicationController redirect_to wiki_page_path(@page.permalink) end + + def variables + keys = Foodsoft::ExpansionVariables.variables.keys + @variables = Hash[keys.map {|k| [k, Foodsoft::ExpansionVariables.get(k)]}] + render 'variables' + end + + private + + def catch_special_pages + if params[:id] == 'Help:Foodsoft_variables' + variables + end + end end diff --git a/plugins/wiki/app/views/pages/_form.html.haml b/plugins/wiki/app/views/pages/_form.html.haml index 368b4d18..fcbd8207 100644 --- a/plugins/wiki/app/views/pages/_form.html.haml +++ b/plugins/wiki/app/views/pages/_form.html.haml @@ -85,5 +85,6 @@ %td(colspan=2) %ul %li!= link_to t('.help.link_table'), '//www.mediawiki.org/wiki/Help:Tables', target: '_blank' + %li!= link_to t('.help.link_variables'), page_path('Help:Foodsoft_variables'), target: '_blank' %li!= link_to t('.help.link_lists'), '//www.mediawiki.org/wiki/Help:Lists', target: '_blank' %li!= link_to t('.help.link_templates'), '//www.mediawiki.org/wiki/Help:Templates', target: '_blank' diff --git a/plugins/wiki/app/views/pages/variables.html.haml b/plugins/wiki/app/views/pages/variables.html.haml new file mode 100644 index 00000000..58946f5e --- /dev/null +++ b/plugins/wiki/app/views/pages/variables.html.haml @@ -0,0 +1,16 @@ +- title t '.title' + +%p= t '.description' + +%table.table.table-hover + %thead + %tr + %th= t '.variable' + %th= t '.value' + %tbody + - @variables.each do |key, value| + %tr + %td + %tt= "{{#{key}}}" + %td + = value