Class: Awestruct::Handlers::BaseTiltHandler
Instance Attribute Summary
Attributes inherited from BaseHandler
#delegate, #site
Instance Method Summary
collapse
Methods inherited from BaseHandler
#content_line_offset, #dependencies, #execute_shell, #front_matter, #inherit_front_matter, #input_mtime, #output_path, #path, #raw_content, #relative_source_path, #stale?, #to_chain
Constructor Details
Returns a new instance of BaseTiltHandler.
9
10
11
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 9
def initialize(site, delegate)
super( site, delegate )
end
|
Instance Method Details
#content_syntax ⇒ Object
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 55
def content_syntax
extension = input_extension[1..-1]
if ( !site[:content_syntax].nil? && !site[:content_syntax].empty?)
syntax = site[:content_syntax][extension]
return syntax.to_sym unless syntax.nil? or syntax.empty?
end
return extension.to_sym
end
|
#double_extension? ⇒ Boolean
HACK: if this is a double file name extension type e.g. html.haml, xml.erb move to default-site.yml?
20
21
22
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 20
def double_extension?
return true if input_extension =~ /haml|slim|erb|mustache/
end
|
34
35
36
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 34
def input_extension
File.extname( source_file_name )
end
|
#options ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 66
def options
opts = {}
in_ext = input_extension[1..-1].to_sym
out_ext = output_extension[1..-1].to_sym
engine_name = Tilt[path].name.gsub(/(Tilt|:|Template)/i, '').downcase.to_sym
engine_opts = site[engine_name]
unless engine_opts.nil?
opts.merge! engine_opts
end
engine_opts_for_output = site["#{engine_name}|#{out_ext}"]
unless engine_opts_for_output.nil?
opts.merge! engine_opts_for_output
end
unless engine_name == in_ext
in_ext_opts = site[in_ext]
unless in_ext_opts.nil?
opts.merge! in_ext_opts
end
in_ext_opts_for_output = site["#{in_ext}|#{out_ext}"]
unless in_ext_opts_for_output.nil?
opts.merge! in_ext_opts_for_output
end
end
return opts
end
|
#output_extension ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 38
def output_extension
return File.extname( File.basename( source_file_name, File.extname( source_file_name ))) if double_extension?
template = Tilt[path]
if !template.nil?
mime = template.default_mime_type
if !mime.nil?
return '.js' if mime.eql? 'application/javascript'
return '.html' if mime.eql? 'text/html'
return '.xml' if mime.eql? 'text/xml'
return '.css' if mime.eql? 'text/css'
return '.html' end
end
return '.html'
end
|
#output_filename ⇒ Object
30
31
32
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 30
def output_filename
simple_name + output_extension
end
|
#rendered_content(context, with_layouts = true) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 104
def rendered_content(context, with_layouts=true)
$LOG.debug "invoking tilt for #{delegate.path.to_s} with_layouts = #{with_layouts}" if $LOG.debug?
template = Tilt::new(delegate.path.to_s, delegate.content_line_offset + 1, options) { |engine|
delegate.rendered_content( context, with_layouts )
}
template.render( context )
end
|
#simple_name ⇒ Object
24
25
26
27
28
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 24
def simple_name
base = File.basename( source_file_name, File.extname( source_file_name ))
return File.basename( base, File.extname( base ) ) if double_extension?
return base
end
|
#source_file_name ⇒ Object
13
14
15
|
# File 'lib/awestruct/handlers/base_tilt_handler.rb', line 13
def source_file_name
File.basename path
end
|