Class: EasyHtmlGenerator::Generator::Compile::Haml
- Inherits:
-
Base
- Object
- Base
- EasyHtmlGenerator::Generator::Compile::Haml
show all
- Defined in:
- lib/easy_html_generator/generator/compile/haml.rb
Overview
this generator compiles haml files from src folder and copies them to the dist folder
Defined Under Namespace
Classes: Context, Layout
Instance Attribute Summary
Attributes inherited from Base
#config
Instance Method Summary
collapse
Methods inherited from Base
#dest_path, #do_file, #log, #log_running, #resolve_path_prefix, #src_path, #walk_files
Constructor Details
#initialize(project, config) ⇒ Haml
Returns a new instance of Haml.
14
15
16
17
18
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 14
def initialize(project, config)
super(project, config)
@config.src = project.config.paths.src.views
@config.dest = project.config.paths.dist.views
end
|
Instance Method Details
#compile_file(src, target) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 57
def compile_file(src, target)
file_name = File.basename src
scope = file_name.split('.').first
context = Context.new(@project, @config, scope)
layout = Layout.layout_from_file(@project.src_path_to(:views),
src, @config.renderer)
begin
do_file(src, target, layout, context, scope)
rescue StandardError => e
raise e, "#{e.message} in #{src} ", e.backtrace
end
end
|
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 20
def do_input(input, layout, context, scope, _input_file)
result = layout.render(context, body_class: scope) do
body = Haml::Engine.new(input, @config.renderer)
body.render(context)
end
return result unless @config.minimize
EasyHtmlGenerator::Generator::Minimize::Html.compress result
end
|
#generate ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 43
def generate
return unless @config.enabled
log_running
FileUtils.mkdir_p dest_path
walk_files(File.join(src_path, @config.selector)) do |i, o|
next unless should_do_file? i
compile_file i, o
end
end
|
39
40
41
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 39
def input_to_output_file(i)
super(i).gsub('.html.haml', '.html')
end
|
#should_do_file?(i) ⇒ Boolean
34
35
36
37
|
# File 'lib/easy_html_generator/generator/compile/haml.rb', line 34
def should_do_file?(i)
!File.basename(i).start_with? '_'
end
|