Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Constant Summary collapse
- THEMES_BASE_PATH =
RAILS_ROOT+"/public/themes/"
Instance Attribute Summary collapse
-
#page_html ⇒ Object
readonly
Returns the value of attribute page_html.
Class Method Summary collapse
-
.available_themes ⇒ Object
returns an array with all the available theme names.
- .theme_areas(theme_name) ⇒ Object
-
.theme_body(theme_name) ⇒ Object
returns the theme main file code.
Instance Method Summary collapse
-
#area_names ⇒ Object
of the page.
- #fill_areas ⇒ Object
- #fill_theme_vars ⇒ Object
- #render(mode = :show) ⇒ Object
- #theme_areas ⇒ Object
-
#theme_body ⇒ Object
returns the theme main file code.
-
#to_html ⇒ Object
renders the whole page with its theme and contents.
Instance Attribute Details
#page_html ⇒ Object (readonly)
Returns the value of attribute page_html.
2 3 4 |
# File 'app/models/page.rb', line 2 def page_html @page_html end |
Class Method Details
.available_themes ⇒ Object
returns an array with all the available theme names
87 88 89 |
# File 'app/models/page.rb', line 87 def Page.available_themes Dir.entries(THEMES_BASE_PATH).collect {|f| f.gsub("_", "_") unless (f =~ /\..*/ ) }.compact end |
.theme_areas(theme_name) ⇒ Object
91 92 93 94 95 96 97 |
# File 'app/models/page.rb', line 91 def Page.theme_areas (theme_name) areas_colection = [] (Page.theme_body theme_name).gsub %r{%%area:([a-z_]+)%%} do |match| areas_colection << $1 end return areas_colection end |
.theme_body(theme_name) ⇒ Object
returns the theme main file code
77 78 79 |
# File 'app/models/page.rb', line 77 def Page.theme_body (theme_name) File.open( THEMES_BASE_PATH + theme_name + "/index.html" ).read end |
Instance Method Details
#area_names ⇒ Object
of the page
102 103 104 |
# File 'app/models/page.rb', line 102 def area_names #of the page theme_areas #areas.collect {|area| area.area_name }.compact end |
#fill_areas ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/models/page.rb', line 52 def fill_areas # subsitute areas definition (like %%area:myareaname%%) # with the html for the area elements @page_html.gsub!( %r{%%area:([a-z_]+)%%} ) do || area_name = $1 yield area_name end return @page_html end |
#fill_theme_vars ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/page.rb', line 63 def fill_theme_vars # subsitutes some other %%-style "variables" (see above) @page_html.gsub!( %r{%%([a-z_]+):([a-z_]*)%%} ) do || case $1 when "page" title if $2 == "title" when "theme" THEMES_BASE_PATH[(RAILS_ROOT+"/public").length..-1] + theme_name if $2 == "path" end end return @page_html end |
#render(mode = :show) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/page.rb', line 16 def render( mode = :show ) @page_html = theme_body fill_areas do |area_name| area_html = "" area_html = %(<div class='compages_area' id='area_#{ area_name }'>) if mode == :edit for page_element in page_elements.of_area area_name unless page_element.content.nil? area_html << %(<div class='compages_element' id='element_#{ page_element.id }'>) if mode == :edit area_html << page_element.content.body_to_html area_html << %(</div>) if mode == :edit else page_element.destroy end end area_html << %(</div>) if mode == :edit area_html end fill_theme_vars end |
#theme_areas ⇒ Object
98 99 100 |
# File 'app/models/page.rb', line 98 def theme_areas Page.theme_areas( theme_name ) end |
#theme_body ⇒ Object
returns the theme main file code
82 83 84 |
# File 'app/models/page.rb', line 82 def theme_body Page.theme_body( theme_name ) end |
#to_html ⇒ Object
renders the whole page with its theme and contents
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/page.rb', line 37 def to_html @page_html = theme_body # subsitute areas definition (like %%area:my_area_name%%) # with the html for the area elements @page_html.gsub!( %r{%%area:([a-z_]+)%%} ) do || area_name, area_html = $1, "" for page_element in page_elements.of_area area_name area_html = page_element.content.body_to_html end area_html end fill_theme_vars end |