aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--init.rb4
-rw-r--r--lib/alavetelitheme.rb7
-rw-r--r--lib/config/custom-routes.rb19
-rw-r--r--lib/controller_patches.rb15
-rw-r--r--lib/customstates.rb50
-rw-r--r--lib/model_patches.rb16
-rw-r--r--lib/patch_mailer_paths.rb11
-rw-r--r--lib/public_body_categories_en.rb9
-rw-r--r--lib/views/general/mycontroller.rhtml7
9 files changed, 132 insertions, 6 deletions
diff --git a/init.rb b/init.rb
index 0014c62..ad2cf40 100644
--- a/init.rb
+++ b/init.rb
@@ -1 +1,3 @@
-require "alavetelitheme.rb"
+if ENV["RAILS_ENV"] != "test" # Don't let the theme interfere with Alaveteli specs
+ require "alavetelitheme.rb"
+end
diff --git a/lib/alavetelitheme.rb b/lib/alavetelitheme.rb
index 58defaa..2ba63ce 100644
--- a/lib/alavetelitheme.rb
+++ b/lib/alavetelitheme.rb
@@ -15,6 +15,13 @@ end
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
end
+# Monkey patch app code
+require 'controller_patches.rb'
+require 'model_patches.rb'
+require 'patch_mailer_paths.rb'
+
+# Extend routes
+require 'config/custom-routes.rb'
# Plug theme-specific locale strings
require 'gettext_setup.rb'
diff --git a/lib/config/custom-routes.rb b/lib/config/custom-routes.rb
index 2c1b9cc..b8afebd 100644
--- a/lib/config/custom-routes.rb
+++ b/lib/config/custom-routes.rb
@@ -1,8 +1,17 @@
# Here you can override or add to the pages in the core website
-ActionController::Routing::Routes.draw do |map|
- # Additional help page example
- map.with_options :controller => 'help' do |help|
- help.help_out '/help/help_out', :action => 'help_out'
- end
+
+require 'dispatcher'
+Dispatcher.to_prepare do
+ ActionController::Routing::Routes.draw do |map|
+ # brand new controller example
+ map.with_options :controller => 'general' do |general|
+ general.mycontroller '/mycontroller', :action => 'mycontroller'
+ end
+
+ # Additional help page example
+ map.with_options :controller => 'help' do |help|
+ help.help_out '/help/help_out', :action => 'help_out'
+ end
+ end
end
diff --git a/lib/controller_patches.rb b/lib/controller_patches.rb
new file mode 100644
index 0000000..11b5722
--- /dev/null
+++ b/lib/controller_patches.rb
@@ -0,0 +1,15 @@
+# Add a callback - to be executed before each request in development,
+# and at startup in production - to patch existing app classes.
+# Doing so in init/environment.rb wouldn't work in development, since
+# classes are reloaded, but initialization is not run each time.
+# See http://stackoverflow.com/questions/7072758/plugin-not-reloading-in-development-mode
+#
+require 'dispatcher'
+Dispatcher.to_prepare do
+ # Example adding an instance variable to the frontpage controller
+ GeneralController.class_eval do
+ def mycontroller
+ @say_something = "Greetings friend"
+ end
+ end
+end
diff --git a/lib/customstates.rb b/lib/customstates.rb
new file mode 100644
index 0000000..c09eb8c
--- /dev/null
+++ b/lib/customstates.rb
@@ -0,0 +1,50 @@
+# See `doc/THEMES.md` for more explanation of this file
+# This example adds a "transferred" state to requests.
+
+module InfoRequestCustomStates
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ # Work out what the situation of the request is. In addition to
+ # values of self.described_state, in base Alaveteli can return
+ # these (calculated) values:
+ # waiting_classification
+ # waiting_response_overdue
+ # waiting_response_very_overdue
+ def theme_calculate_status
+ # just fall back to the core calculation
+ return self.base_calculate_status
+ end
+
+ # Mixin methods for InfoRequest
+ module ClassMethods
+ def theme_display_status(status)
+ if status == 'transferred'
+ _("Transferred.")
+ else
+ raise _("unknown status ") + status
+ end
+ end
+
+ def theme_extra_states
+ return ['transferred']
+ end
+ end
+end
+
+module RequestControllerCustomStates
+
+ def theme_describe_state(info_request)
+ # called after the core describe_state code. It should
+ # end by raising an error if the status is unknown
+ if info_request.calculate_status == 'transferred'
+ flash[:notice] = _("Authority has transferred your request to a different public body.")
+ redirect_to request_url(@info_request)
+ else
+ raise "unknown calculate_status " + info_request.calculate_status
+ end
+ end
+
+end
diff --git a/lib/model_patches.rb b/lib/model_patches.rb
new file mode 100644
index 0000000..694f54d
--- /dev/null
+++ b/lib/model_patches.rb
@@ -0,0 +1,16 @@
+# Add a callback - to be executed before each request in development,
+# and at startup in production - to patch existing app classes.
+# Doing so in init/environment.rb wouldn't work in development, since
+# classes are reloaded, but initialization is not run each time.
+# See http://stackoverflow.com/questions/7072758/plugin-not-reloading-in-development-mode
+#
+require 'dispatcher'
+Dispatcher.to_prepare do
+ OutgoingMessage.class_eval do
+ # Add intro paragraph to new request template
+ def default_letter
+ return nil if self.message_type == 'followup'
+ #"If you uncomment this line, this text will appear as default text in every message"
+ end
+ end
+end
diff --git a/lib/patch_mailer_paths.rb b/lib/patch_mailer_paths.rb
new file mode 100644
index 0000000..d0a0b23
--- /dev/null
+++ b/lib/patch_mailer_paths.rb
@@ -0,0 +1,11 @@
+# Add a callback - to be executed before each request in development,
+# and at startup in production - to patch existing app classes.
+# See http://stackoverflow.com/questions/7072758/plugin-not-reloading-in-development-mode
+#
+require 'dispatcher'
+Dispatcher.to_prepare do
+ # Override mailer templates with theme ones. Note doing this in a before_filter,
+ # as we do with the controller paths, doesn't seem to have any effect when
+ # running in production
+ ActionMailer::Base.view_paths.unshift File.join(File.dirname(__FILE__), "views")
+end
diff --git a/lib/public_body_categories_en.rb b/lib/public_body_categories_en.rb
index f3c0aa4..a8969ba 100644
--- a/lib/public_body_categories_en.rb
+++ b/lib/public_body_categories_en.rb
@@ -1,3 +1,12 @@
+# The PublicBodyCategories structure works like this:
+# [
+# "Main category name",
+# [ "tag_to_use_as_category", "Sub category title", "sentence that can describes things in this subcategory" ],
+# [ "another_tag", "Second sub category title", "another descriptive sentence for things in this subcategory"],
+# "Another main category name",
+# [ "another_tag_2", "Another sub category title", "another descriptive sentence"]
+# ])
+
PublicBodyCategories.add(:en, [
"Silly ministries",
[ "useless_agency", "Useless ministries", "a useless ministry" ],
diff --git a/lib/views/general/mycontroller.rhtml b/lib/views/general/mycontroller.rhtml
new file mode 100644
index 0000000..ad642d3
--- /dev/null
+++ b/lib/views/general/mycontroller.rhtml
@@ -0,0 +1,7 @@
+<% @title = "My new controller" %>
+
+<h1>My new controller</h1>
+
+<p>This is a view of a controller that does almost nothing, except output the words <code><%= @say_something %></code></p>
+
+