diff options
| author | hukl <contact@smyck.org> | 2009-02-28 13:34:23 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-02-28 13:34:23 +0100 |
| commit | bd9067272e1bd5a8651c5b9fa66881782406c54c (patch) | |
| tree | cb9bb1961ab4b376636eb6b3e76312991b125c89 /app/helpers | |
| parent | cc74db30d930b0eaaf0ac29b19ddd452ea0c1462 (diff) | |
added custom partials to aggregators, added test and refactored some methods
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/content_helper.rb | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb index 9800471..7747609 100644 --- a/app/helpers/content_helper.rb +++ b/app/helpers/content_helper.rb | |||
| @@ -33,6 +33,8 @@ module ContentHelper | |||
| 33 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") | 33 | options[splitted_data[0].to_sym] = splitted_data[1].gsub(/\"/, "") |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | options[:partial] = select_partial( options[:partial] ) | ||
| 37 | |||
| 36 | content.sub(tag, render_collection(options)) | 38 | content.sub(tag, render_collection(options)) |
| 37 | else | 39 | else |
| 38 | content | 40 | content |
| @@ -47,8 +49,31 @@ module ContentHelper | |||
| 47 | # from Page.aggregate(options) with a given partial | 49 | # from Page.aggregate(options) with a given partial |
| 48 | def render_collection options | 50 | def render_collection options |
| 49 | render( | 51 | render( |
| 50 | :partial => 'content/article', | 52 | :partial => options[:partial], |
| 51 | :collection => Page.aggregate(options) | 53 | :collection => Page.aggregate(options), |
| 54 | :as => :page | ||
| 55 | ) | ||
| 56 | end | ||
| 57 | |||
| 58 | private | ||
| 59 | |||
| 60 | # Either return a custom partial path if it exsits or default to the standard | ||
| 61 | # partial | ||
| 62 | def select_partial partial | ||
| 63 | if partial && partial_exists?( partial ) | ||
| 64 | return "custom_templates/partials/#{partial}" | ||
| 65 | else | ||
| 66 | return 'content/article' | ||
| 67 | end | ||
| 68 | end | ||
| 69 | |||
| 70 | # Check if a custom partial exists in the proper location | ||
| 71 | def partial_exists? partial | ||
| 72 | File.exist?( | ||
| 73 | File.join( | ||
| 74 | RAILS_ROOT, 'app', 'views', 'custom_templates', 'partials', "_#{partial}.html.erb" | ||
| 75 | ) | ||
| 52 | ) | 76 | ) |
| 53 | end | 77 | end |
| 78 | |||
| 54 | end | 79 | end |
