Method: Moka::Compiler#compile
- Defined in:
- lib/commands/lib/compiler.rb
#compile(group, page_name, manifest = nil) ⇒ Object
Compile page into a string and returns it
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/commands/lib/compiler.rb', line 29 def compile(group, page_name, manifest = nil) path = nil if manifest.nil? manifest = YAML.load_file(File.("manifest.yml", MOKA_ROOT)) end m_page_data = manifest["site"][group][page_name] layout = m_page_data["layout"].nil? ? "layout" : m_page_data["layout"] path = m_page_data["path"] # load layout file ext = nil layout_dir = File.join [group, page_name] while ext.nil? do if File.exist?(File.("project/site/#{layout_dir}/#{layout}.erb", MOKA_ROOT)) layout_file = File.new(File.("project/site/#{layout_dir}/#{layout}.erb", MOKA_ROOT), "r") ext = "erb" elsif File.exist?(File.("project/site/#{layout_dir}/#{layout}.haml", MOKA_ROOT)) layout_file = File.new(File.("project/site/#{layout_dir}/#{layout}.haml", MOKA_ROOT), "r") ext = "haml" end if layout_dir == "" and ext.nil? puts "ERROR: cannot find layout file #{layout}.erb or #{layout}.haml" exit end layout_dir = File.dirname layout_dir if layout_dir == "." layout_dir = "" end end page_string = "" layout_file.each_line do |line| page_string += line end layout_file.close # this object is the scope in which erb/haml code will be evaluated code_evaluator = PageScope.new(Moka::Utilities.deepcopy(manifest), group, page_name ) return Moka::Utilities.eval_erb_haml(page_string, ext, code_evaluator.get_binding) end |