Class: Soundwave::Page
- Inherits:
-
Object
- Object
- Soundwave::Page
- Defined in:
- lib/soundwave.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #base_path ⇒ Object
-
#initialize(site, path) ⇒ Page
constructor
A new instance of Page.
- #output_path ⇒ Object
- #read_data ⇒ Object
- #relative_path ⇒ Object
- #render ⇒ Object
- #write(destination) ⇒ Object
Constructor Details
#initialize(site, path) ⇒ Page
Returns a new instance of Page.
70 71 72 73 |
# File 'lib/soundwave.rb', line 70 def initialize(site, path) @site = site @path = Pathname(path). end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
68 69 70 |
# File 'lib/soundwave.rb', line 68 def path @path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
68 69 70 |
# File 'lib/soundwave.rb', line 68 def site @site end |
Instance Method Details
#base_path ⇒ Object
83 84 85 |
# File 'lib/soundwave.rb', line 83 def base_path relative_path.sub(".mustache",'') end |
#output_path ⇒ Object
79 80 81 |
# File 'lib/soundwave.rb', line 79 def output_path relative_path.sub('.mustache','.html') end |
#read_data ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/soundwave.rb', line 97 def read_data if data_file = site.data_trail.find(base_path) case File.extname(data_file) when ".yml" data = YAML.load(File.read(data_file)) when ".json" data = MultiJson.decode(File.read(data_file)) else data = {} end else data = {} end end |
#relative_path ⇒ Object
75 76 77 |
# File 'lib/soundwave.rb', line 75 def relative_path @path.relative_path_from(site.source).to_s end |
#render ⇒ Object
87 88 89 |
# File 'lib/soundwave.rb', line 87 def render Soundwave::Mustache.new(self).render(@path.read, self.read_data) end |
#write(destination) ⇒ Object
91 92 93 94 95 |
# File 'lib/soundwave.rb', line 91 def write(destination) destination = Pathname(destination) puts "#{relative_path} => #{destination.relative_path_from(site.source)}" File.open(destination, "w") { |f| f.write(self.render) } end |