Class: StaticCms::Article
- Inherits:
-
Object
- Object
- StaticCms::Article
- Extended by:
- RubyPatch::AutoLoad
- Defined in:
- lib/static_cms/article.rb
Constant Summary collapse
- PARAMS_DEFAULT =
{ 'title' => '', }
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pages ⇒ Object
Returns the value of attribute pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ Article
constructor
A new instance of Article.
Constructor Details
#initialize(name) ⇒ Article
Returns a new instance of Article.
18 19 20 21 22 23 24 25 26 |
# File 'lib/static_cms/article.rb', line 18 def initialize(name) @pages = [] @name = name @file = File.join('articles', name) + '.html.yhaml' yaml, @data = File.read(@file).split(/^\.\.\.$/, 2) params = PARAMS_DEFAULT.merge(YAML.load(yaml)) params.each{|k, v| instance_variable_set("@#{k}", v)} self.class.alist[@name] = self end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
15 16 17 |
# File 'lib/static_cms/article.rb', line 15 def data @data end |
#file ⇒ Object
Returns the value of attribute file.
15 16 17 |
# File 'lib/static_cms/article.rb', line 15 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
15 16 17 |
# File 'lib/static_cms/article.rb', line 15 def name @name end |
#pages ⇒ Object
Returns the value of attribute pages.
15 16 17 |
# File 'lib/static_cms/article.rb', line 15 def pages @pages end |
Class Method Details
.alist ⇒ Object
7 8 9 |
# File 'lib/static_cms/article.rb', line 7 def self.alist @alist end |
.load ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/static_cms/article.rb', line 28 def self.load `git ls-files articles`.split\ .select{|f| f =~ /\.html\.yhaml\z/}\ .map{|f| f.sub(/\Aarticles\//, '')}\ .map{|f| File.basename(f, '.html.yhaml')}\ .each{|name| self.new(name)} end |
.use(page, name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/static_cms/article.rb', line 36 def self.use(page, name) self.load unless self.alist.has_key?(name) raise ArgumentError, name unless self.alist.has_key?(name) article = self.alist[name] article.pages << page article end |