Class: Awestruct::Page
Constant Summary
AStructMixin::UNTRACKED_KEYS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from AStruct
#hash
#[], #cascade_for_nils!, extended, #key?, #method_missing, #transform_entry
Constructor Details
#initialize(site, handler = nil) ⇒ Page
Returns a new instance of Page.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Awestruct::AStructMixin
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
15
16
17
|
# File 'lib/awestruct/page.rb', line 15
def dependencies
@dependencies
end
|
#handler ⇒ Object
Returns the value of attribute handler.
14
15
16
|
# File 'lib/awestruct/page.rb', line 14
def handler
@handler
end
|
#site ⇒ Object
Returns the value of attribute site.
13
14
15
|
# File 'lib/awestruct/page.rb', line 13
def site
@site
end
|
Instance Method Details
#==(other_page) ⇒ Object
176
177
178
|
# File 'lib/awestruct/page.rb', line 176
def ==(other_page)
self.object_id == other_page.object_id
end
|
#all_dependencies ⇒ Object
114
115
116
|
# File 'lib/awestruct/page.rb', line 114
def all_dependencies
@dependencies + handler.dependencies
end
|
#collective_dependencies_mtime ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/awestruct/page.rb', line 102
def collective_dependencies_mtime
t = nil
@dependencies.each do |e|
if ( t == nil )
t = e.mtime
elsif ( t < e.mtime )
t = e.mtime
end
end
t
end
|
#content(with_layouts = false) ⇒ Object
172
173
174
|
# File 'lib/awestruct/page.rb', line 172
def content(with_layouts=false)
rendered_content( create_context(), with_layouts )
end
|
#content_syntax ⇒ Object
118
119
120
|
# File 'lib/awestruct/page.rb', line 118
def content_syntax
handler.content_syntax
end
|
#create_context(content = '') ⇒ Object
38
39
40
41
42
|
# File 'lib/awestruct/page.rb', line 38
def create_context(content='')
context = Awestruct::Context.new( :site=>site, :page=>self, :content=>content )
site.engine.pipeline.mixin_helpers( context )
context
end
|
#inherit_front_matter_from(hash) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/awestruct/page.rb', line 44
def inherit_front_matter_from(hash)
hash.each do |k,v|
$LOG.debug "#{self.output_path} overwrite key: #{k}:#{self[k]} -> #{v}" if ( key?( k ) and !self[k].nil? and !self[k].eql? v) if $LOG.debug?
unless ( key?( k ) )
self[k.to_sym] = v
end
end
end
|
98
99
100
|
# File 'lib/awestruct/page.rb', line 98
def input_mtime
handler.input_mtime( self )
end
|
#inspect ⇒ Object
34
35
36
|
# File 'lib/awestruct/page.rb', line 34
def inspect
"Awestruct::Page{ #{self.object_id}: output_path=>#{output_path}, source_path=>#{source_path}, layout=>#{layout} }"
end
|
#output_extension ⇒ Object
76
77
78
|
# File 'lib/awestruct/page.rb', line 76
def output_extension
handler.output_extension
end
|
#output_filename ⇒ Object
80
81
82
|
# File 'lib/awestruct/page.rb', line 80
def output_filename
handler.output_filename
end
|
#output_path ⇒ Object
65
66
67
|
# File 'lib/awestruct/page.rb', line 65
def output_path
(@output_path || handler.output_path).to_s
end
|
#output_path=(path) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/awestruct/page.rb', line 69
def output_path=(path)
case ( path )
when Pathname then @output_path = path
else @output_path = Pathname.new( path )
end
end
|
#prepare! ⇒ Object
30
31
32
|
# File 'lib/awestruct/page.rb', line 30
def prepare!
handler.inherit_front_matter( self )
end
|
#raw_content ⇒ Object
122
123
124
|
# File 'lib/awestruct/page.rb', line 122
def raw_content
handler.raw_content
end
|
#relative_source_path ⇒ Object
53
54
55
|
# File 'lib/awestruct/page.rb', line 53
def relative_source_path
@relative_source_path || handler.relative_source_path
end
|
#relative_source_path=(path) ⇒ Object
57
58
59
|
# File 'lib/awestruct/page.rb', line 57
def relative_source_path=(path)
@relative_source_path = path
end
|
#rendered_content(context = create_context(), with_layouts = true) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/awestruct/page.rb', line 126
def rendered_content(context=create_context(), with_layouts=true)
if context.site.config.track_dependencies
Awestruct::Dependencies.push_page( self )
end
c = nil
begin
$LOG.debug "calling rendered_content on handler for page #{self.output_path}" if $LOG.debug?
c = handler.rendered_content( context, with_layouts )
rescue StandardError => e
lineno = nil
if e.respond_to?(:lineno)
lineno = e.lineno
elsif e.respond_to?(:line)
lineno = e.line
end
if lineno
if self.handler.respond_to?(:content_line_offset)
lineno += self.handler.content_line_offset
end
end
lineinfo = lineno ? " at line #{lineno}" : ''
raise StandardError, "ERROR: Failed to render: #{self.relative_source_path}#{lineinfo}\n#{e.class}: #{e.message.rstrip}\n" + e.backtrace.join("\n")
end
if context.site.config.track_dependencies
Awestruct::Dependencies.pop_page
Awestruct::Dependencies.track_dependencies = false
if with_layouts
@dependencies.content_hash = Digest::SHA2.hexdigest(c)
tmp_page = Awestruct::Page.new @site
@handler.inherit_front_matter(tmp_page)
string_to_hash = tmp_page.to_a.each{|x| x[0]=x[0].to_s; x[1]=x[1].to_s; x}.sort.to_s
hash = Digest::SHA2.hexdigest(string_to_hash)
@dependencies.key_hash = hash
end
Awestruct::Dependencies.track_dependencies = true
end
c
end
|
#simple_name ⇒ Object
61
62
63
|
# File 'lib/awestruct/page.rb', line 61
def simple_name
handler.simple_name
end
|
#source_path ⇒ Object
84
85
86
|
# File 'lib/awestruct/page.rb', line 84
def source_path
handler.path.to_s
end
|
#stale? ⇒ Boolean
88
89
90
|
# File 'lib/awestruct/page.rb', line 88
def stale?
handler.stale? || @dependencies.dependencies.any?(&:stale?)
end
|
#stale_output?(output_path) ⇒ Boolean
92
93
94
95
96
|
# File 'lib/awestruct/page.rb', line 92
def stale_output?(output_path)
return true if ! File.exist?( output_path )
return true if input_mtime > File.mtime( output_path )
false
end
|