aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2013-12-25 00:15:57 +0100
committerHarald Eilertsen <haraldei@anduin.net>2013-12-25 00:15:57 +0100
commitde85692eb4cb19112e5b3a6d68c8867c65ff0da0 (patch)
tree2427f6544d15f28550256c5af8b4817bcb7e1dd8 /app/models
parent771532124d5486eb78c22f1c638ff647883d46b8 (diff)
downloadhmnoweb-de85692eb4cb19112e5b3a6d68c8867c65ff0da0.tar.gz
hmnoweb-de85692eb4cb19112e5b3a6d68c8867c65ff0da0.tar.bz2
hmnoweb-de85692eb4cb19112e5b3a6d68c8867c65ff0da0.zip
Clean up sidebar modules.
Rewrite the _sidebar_module partial to render only one module, and to not make any assumptions about the contents of a module. (Except that it has a title and a body.) Move the actual module logic into model classes, and use the ActiveModel magic to have it find it's own partial. Now we have the view logic for each module in it's own partial that in turn renders as part of the _sidebar_module partial. Only implementation this far is the blog-category module listing the latest blog entries within each category.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/sidebar_blog_category.rb12
-rw-r--r--app/models/sidebar_module.rb13
2 files changed, 25 insertions, 0 deletions
diff --git a/app/models/sidebar_blog_category.rb b/app/models/sidebar_blog_category.rb
new file mode 100644
index 0000000..53d15af
--- /dev/null
+++ b/app/models/sidebar_blog_category.rb
@@ -0,0 +1,12 @@
+class SidebarBlogCategory < SidebarModule
+ def initialize(category)
+ @title = category.title
+ @position = category.sidebar_position
+ @posts = category.posts.recent(5)
+ end
+
+ def body
+ @posts
+ end
+
+end
diff --git a/app/models/sidebar_module.rb b/app/models/sidebar_module.rb
new file mode 100644
index 0000000..1e9bde1
--- /dev/null
+++ b/app/models/sidebar_module.rb
@@ -0,0 +1,13 @@
+class SidebarModule
+ attr_reader :title, :body, :position
+
+ def initialize(title, body, pos)
+ @title = title
+ @body = body
+ @position = pos
+ end
+
+ def to_partial_path
+ "sidebar_modules/#{self.class.to_s.underscore}"
+ end
+end