Class: Scms::ScmsParser
- Inherits:
-
Object
- Object
- Scms::ScmsParser
- Defined in:
- lib/scms/scms-parser.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize(template, model = Hash.new) ⇒ ScmsParser
constructor
A new instance of ScmsParser.
- #parse(viewpath = nil) ⇒ Object
Constructor Details
#initialize(template, model = Hash.new) ⇒ ScmsParser
Returns a new instance of ScmsParser.
18 19 20 21 22 23 24 25 26 |
# File 'lib/scms/scms-parser.rb', line 18 def initialize (template, model = Hash.new) @template = template if model.class == OpenStruct @model = model else @model = OpenStruct.new(model.clone) end end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/scms/scms-parser.rb', line 8 def model @model end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/scms/scms-parser.rb', line 8 def template @template end |
Instance Method Details
#parse(viewpath = nil) ⇒ Object
28 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 72 73 74 75 76 77 78 79 |
# File 'lib/scms/scms-parser.rb', line 28 def parse(viewpath = nil) result = "" if @template != nil begin page = @model erb = ERB.new(@template) result = erb.result(page.instance_eval { binding }) result = ScmsUtils.toUTF8(result) # only do cms click edit on sub views not layout templates if page.view != nil if page.mode == "cms" if viewpath != nil result = "<div class='cms' data-view='#{viewpath}' data-page='#{page.url}'>#{result}</div>" if page.allowEdit end end end rescue StandardError => e #puts "page: #{page}" ScmsUtils.errLog("Critical Error: Could not parse template") #ScmsUtils.errLog(e.message) result = "<div style='border: 1px solid #A8A8A8; border-radius:8px; background-color: #FFFFE0; box-shadow: 5px 5px 3px #CDCDCD; padding: 15px; margin: 15px;'>" result += "<p>Critical Error: Could not parse template</p>" result += "<code><pre>" result += e. result += "\n\n" result += e.inspect result += "\n\n" result += "Valid template properties are:\n" @model.marshal_dump.each do |key, value| result += "- page.#{key}\n" puts "nil value foy key: #{key}" if value == nil singleton_class.send(:define_method, key) { value } end result += "\n\n" result += e.backtrace.join("\n") result += "</pre></code></div>" result += "\n\n" result += template rescue Exception => e puts "Problem with template - check property exists" end else ScmsUtils.log("Error: Can not parse template. Template is empty") end return result end |