Class: Ichiban::Script
- Inherits:
-
Object
- Object
- Ichiban::Script
- Defined in:
- lib/ichiban/scripts.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#generate(template_path, dest_path, ivars) ⇒ Object
Automatically appends .html to dest_path.
-
#initialize(path) ⇒ Script
constructor
Takes an absolute path.
- #run ⇒ Object
Constructor Details
#initialize(path) ⇒ Script
Takes an absolute path
39 40 41 |
# File 'lib/ichiban/scripts.rb', line 39 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
43 44 45 |
# File 'lib/ichiban/scripts.rb', line 43 def path @path end |
Instance Method Details
#generate(template_path, dest_path, ivars) ⇒ Object
Automatically appends .html to dest_path
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ichiban/scripts.rb', line 16 def generate(template_path, dest_path, ivars) dest_path += '.html' ext_to_remove = File.extname(dest_path) web_path = '/' + dest_path.sub(/#{ext_to_remove}$/, '') + '/' compiler = Ichiban::HTMLCompiler.new( Ichiban::HTMLFile.new( File.join('html', template_path) ) ) compiler.ivars = {:_current_path => web_path}.merge(ivars) html = compiler.compile_to_str abs_dest_path = File.join(Ichiban.project_root, 'compiled', dest_path) FileUtils.mkdir_p File.dirname(abs_dest_path) File.open(abs_dest_path, 'w') do |f| f << html end Ichiban.logger.compilation( File.join(Ichiban.project_root, 'html', template_path), File.join(Ichiban.project_root, 'compiled', dest_path) ) end |
#run ⇒ Object
45 46 47 48 49 50 |
# File 'lib/ichiban/scripts.rb', line 45 def run instance_eval( File.read(@path), @path ) end |