Class: Gumdrop::Content
- Inherits:
-
Object
- Object
- Gumdrop::Content
- Defined in:
- lib/gumdrop/content.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ext ⇒ Object
Returns the value of attribute ext.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#full_path ⇒ Object
Returns the value of attribute full_path.
-
#ignored ⇒ Object
Returns the value of attribute ignored.
-
#level ⇒ Object
Returns the value of attribute level.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#site ⇒ Object
Returns the value of attribute site.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#source_filename ⇒ Object
Returns the value of attribute source_filename.
-
#template ⇒ Object
Returns the value of attribute template.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #copyTo(output, layout = nil, opts = {}) ⇒ Object
-
#initialize(path, site, params = {}) ⇒ Content
constructor
A new instance of Content.
- #mtime ⇒ Object
- #render(context = nil, ignore_layout = false, reset_context = true, locals = {}) ⇒ Object
- #renderTo(context, output_path, filters = [], opts = {}) ⇒ Object
- #to_s ⇒ Object
- #useLayout? ⇒ Boolean
Constructor Details
#initialize(path, site, params = {}) ⇒ Content
Returns a new instance of Content.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gumdrop/content.rb', line 20 def initialize(path, site, params={}) @site= site @params= HashObject.new params @full_path= path @ignored= false @path= get_source_path @level= (@path.split('/').length - 1) @source_filename= File.basename path @filename= get_target_filename @type= File.extname @source_filename @ext= File.extname @filename @uri= get_uri @slug=@uri.gsub('/', '-').gsub(@ext, '') @template= unless Tilt[path].nil? Tilt.new path else nil end end |
Instance Attribute Details
#ext ⇒ Object
Returns the value of attribute ext.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def ext @ext end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def filename @filename end |
#full_path ⇒ Object
Returns the value of attribute full_path.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def full_path @full_path end |
#ignored ⇒ Object
Returns the value of attribute ignored.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def ignored @ignored end |
#level ⇒ Object
Returns the value of attribute level.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def level @level end |
#params ⇒ Object
Returns the value of attribute params.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def path @path end |
#site ⇒ Object
Returns the value of attribute site.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def site @site end |
#slug ⇒ Object
Returns the value of attribute slug.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def slug @slug end |
#source_filename ⇒ Object
Returns the value of attribute source_filename.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def source_filename @source_filename end |
#template ⇒ Object
Returns the value of attribute template.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def template @template end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def type @type end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/gumdrop/content.rb', line 6 def uri @uri end |
Instance Method Details
#copyTo(output, layout = nil, opts = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gumdrop/content.rb', line 68 def copyTo(output, layout=nil, opts={}) do_copy= if File.exists? output !FileUtils.identical? @full_path, output else true end if do_copy @site.report " Copying: #{@uri}", :warning FileUtils.cp_r @full_path, output, opts else @site.report " (same): #{@uri}", :info end end |
#mtime ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/gumdrop/content.rb', line 82 def mtime if File.exists? @full_path File.new(@full_path).mtime else Time.now end end |
#render(context = nil, ignore_layout = false, reset_context = true, locals = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gumdrop/content.rb', line 40 def render(context=nil, ignore_layout=false, reset_context=true, locals={}) context= @site.render_context if context.nil? if reset_context default_layout= (@ext == '.css' or @ext == '.js' or @ext == '.xml') ? nil : 'site' context.reset_data 'current_depth'=>@level, 'current_slug'=>@slug, 'page'=>self, 'layout'=>default_layout, 'params'=>self.params end context.set_content self, locals content= @template.render(context) return content if ignore_layout layout= context.get_template() while !layout.nil? content = layout.template.render(context, content:content) { content } layout= context.get_template() end content end |
#renderTo(context, output_path, filters = [], opts = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/gumdrop/content.rb', line 57 def renderTo(context, output_path, filters=[], opts={}) return copyTo(output_path, opts) unless useLayout? @site.report " Rendering: #{@uri}", :warning output= render(context) filters.each {|f| output= f.call(output, self) } File.open output_path, 'w' do |f| f.write output end end |
#to_s ⇒ Object
94 95 96 |
# File 'lib/gumdrop/content.rb', line 94 def to_s @uri end |
#useLayout? ⇒ Boolean
90 91 92 |
# File 'lib/gumdrop/content.rb', line 90 def useLayout? !@template.nil? end |