Class: StaticCms::Page
- Inherits:
-
Object
- Object
- StaticCms::Page
- Extended by:
- RubyPatch::AutoLoad
- Defined in:
- lib/static_cms/page.rb
Constant Summary collapse
- PARAMS_DEFAULT =
{ 'visible' => true, 'title' => '', 'template' => 'default', 'articles' => [], 'statics' => [], 'sources' => [], 'base' => nil, }
Instance Attribute Summary collapse
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#name ⇒ Object
Returns the value of attribute name.
-
#site ⇒ Object
Returns the value of attribute site.
-
#template_file ⇒ Object
Returns the value of attribute template_file.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(site, name, params = {}) ⇒ Page
constructor
A new instance of Page.
Constructor Details
#initialize(site, name, params = {}) ⇒ Page
Returns a new instance of Page.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/static_cms/page.rb', line 20 def initialize(site, name, params = {}) @site = site @name = name @dir = File.join("root", @name) params = PARAMS_DEFAULT.merge(params) @template = params.delete('template') @template_file = File.join('templates', @template) + '.html.haml' @articles = params.delete('articles').map{|name| ::StaticCms::Article.use(self, name)} @statics = params.delete('statics').map{|file| File.join('statics', file)} @sources = params.delete('sources').map{|file| File.join('sources', file)} @base = params.delete('base') || @site.www params.each{|k, v| instance_variable_set("@#{k}", v) } end |
Instance Attribute Details
#dir ⇒ Object
Returns the value of attribute dir.
17 18 19 |
# File 'lib/static_cms/page.rb', line 17 def dir @dir end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/static_cms/page.rb', line 17 def name @name end |
#site ⇒ Object
Returns the value of attribute site.
17 18 19 |
# File 'lib/static_cms/page.rb', line 17 def site @site end |
#template_file ⇒ Object
Returns the value of attribute template_file.
17 18 19 |
# File 'lib/static_cms/page.rb', line 17 def template_file @template_file end |
Instance Method Details
#generate ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/static_cms/page.rb', line 36 def generate FileUtils.mkdir_p(@dir) FileUtils.chmod(0755, @dir) if @visible @statics.each{|file| cp_if_new(file)} @sources.each{|file| compile(file)} template_file = @template_file else @statics.each{|file| FileUtils.rm_rf(static_target(file))} @sources.each{|file| FileUtils.rm_rf(compile_target(file))} template_file = 'templates/moved.html.haml' end html = ::Haml::Engine.new(File.read(template_file)).render(self) target = File.join(@dir, 'index.html') open(target, 'w'){|io| io.write(html) io.flush io.fsync } end |