Class: Microengine::Assambler
- Inherits:
-
Object
- Object
- Microengine::Assambler
- Defined in:
- lib/assambler.rb
Overview
Create XHTML pages from layouts and content
Instance Attribute Summary collapse
-
#config ⇒ Object
writeonly
Sets the attribute config.
-
#logger ⇒ Object
writeonly
Sets the attribute logger.
Instance Method Summary collapse
-
#assamble(path, layout_name, lang, header, body, langs) ⇒ Object
Create XHTML page by layout and content.
-
#cache_file(path, lang, langs) ⇒ Object
Cache content for some lang in path.
-
#refresh ⇒ Object
Create XHTML pages from layouts and content.
Instance Attribute Details
#config=(value) ⇒ Object (writeonly)
Sets the attribute config
27 28 29 |
# File 'lib/assambler.rb', line 27 def config=(value) @config = value end |
#logger=(value) ⇒ Object (writeonly)
Sets the attribute logger
28 29 30 |
# File 'lib/assambler.rb', line 28 def logger=(value) @logger = value end |
Instance Method Details
#assamble(path, layout_name, lang, header, body, langs) ⇒ Object
Create XHTML page by layout and content
82 83 84 85 86 87 88 89 90 |
# File 'lib/assambler.rb', line 82 def assamble(path, layout_name, lang, header, body, langs) layout = get_layout layout_name if layout[lang].nil? raise "There isn't translation in '#{lang}' for #{layout_name}" end translation = layout[lang] languages = languages_html langs, lang, layout layout[:layout].result(binding) end |
#cache_file(path, lang, langs) ⇒ Object
Cache content for some lang in path
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 72 73 74 75 76 77 78 79 |
# File 'lib/assambler.rb', line 47 def cache_file(path, lang, langs) file_path = MICROENGINE_ROOT + '/content' + path begin layout = IO.read(file_path + 'layout').strip rescue raise "Can't read layout file in /content#{path}. Please ensure that #{path}layout exists and is chmod 644" end begin header = IO.read(file_path + lang + '.header') rescue raise "Can't read #{lang}.header file in /content#{path}. Please ensure that #{path}#{lang}.header exists and is chmod 644" end begin body = IO.read(file_path + lang + '.body') rescue raise "Can't read #{lang}.body file in /content#{path}. Please ensure that #{path}#{lang}.body exists and is chmod 644" end begin content = assamble path, layout, lang, header, body, langs rescue Exception => e raise "Error in /content#{path}: " + e. end begin io = File.new(MICROENGINE_ROOT + "/cache#{path}content.#{lang}.html", 'w') io.write content io.close rescue raise "Can't write to /cache#{path}content.#{lang}.html . Ensure that /cache/ dir and all files inside is chmod 0666." end end |
#refresh ⇒ Object
Create XHTML pages from layouts and content
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/assambler.rb', line 31 def refresh @layouts = {} begin unless File.directory? MICROENGINE_ROOT + '/cache/' FileUtils.mkdir MICROENGINE_ROOT + '/cache/' end FileUtils.rm_r Dir.glob(MICROENGINE_ROOT + '/cache/*') rescue raise "Can't delete and create /cache/ dir. Ensure that it is chmod 0666." end cache_dir '/' end |