Class: FabulatorPage
- Inherits:
-
Page
- Object
- Page
- FabulatorPage
- Defined in:
- app/models/fabulator_page.rb
Constant Summary collapse
- XML_PART_NAME =
need a reasonable name for the XML part
'extended'
Instance Attribute Summary collapse
-
#c_state_machine ⇒ Object
Returns the value of attribute c_state_machine.
-
#inner_content ⇒ Object
Returns the value of attribute inner_content.
-
#resource_ln ⇒ Object
Returns the value of attribute resource_ln.
Instance Method Summary collapse
-
#cache? ⇒ Boolean
create tags to access filtered data in page display might also create tags for form fields, etc., so it’s easy to create a form and fill in data.
- #fabulator_context ⇒ Object
- #fabulator_context=(c) ⇒ Object
- #find_by_url(url, live = true, clean = false) ⇒ Object
- #headers ⇒ Object
- #missing_args ⇒ Object
- #render_snippet(p) ⇒ Object
- #response_code ⇒ Object
- #state_machine ⇒ Object
- #url ⇒ Object
Instance Attribute Details
#c_state_machine ⇒ Object
Returns the value of attribute c_state_machine.
13 14 15 |
# File 'app/models/fabulator_page.rb', line 13 def c_state_machine @c_state_machine end |
#inner_content ⇒ Object
Returns the value of attribute inner_content.
2 3 4 |
# File 'app/models/fabulator_page.rb', line 2 def inner_content @inner_content end |
#resource_ln ⇒ Object
Returns the value of attribute resource_ln.
13 14 15 |
# File 'app/models/fabulator_page.rb', line 13 def resource_ln @resource_ln end |
Instance Method Details
#cache? ⇒ Boolean
create tags to access filtered data in page display might also create tags for form fields, etc., so it’s easy to create a form and fill in data
19 20 21 |
# File 'app/models/fabulator_page.rb', line 19 def cache? false end |
#fabulator_context ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/fabulator_page.rb', line 72 def fabulator_context if @roots.nil? @roots = { } end if @roots['data'].nil? @roots['data'] = Fabulator::Expr::Node.new('data', @roots, nil, []) ctx = Fabulator::Expr::Context.new ctx.root = @roots['data'] ctx.traverse_path(['resource'], true).first.value = self.resource_ln if self.resource_ln self.state_machine.init_context(ctx) end @roots['data'] end |
#fabulator_context=(c) ⇒ Object
87 88 89 90 91 |
# File 'app/models/fabulator_page.rb', line 87 def fabulator_context=(c) fc = self.fabulator_context @roots = { } if @roots.nil? @roots['data'] = c end |
#find_by_url(url, live = true, clean = false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/fabulator_page.rb', line 23 def find_by_url(url, live = true, clean = false) p = super return p if !p.nil? && !p.is_a?(FileNotFoundPage) url = clean_url(url) if clean if url =~ %r{^#{ self.url }([-_0-9a-zA-Z]+)/?$} self.resource_ln = $1 return self else return p end end |
#headers ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/fabulator_page.rb', line 93 def headers if @resetting_context { :location => self.url, } elsif @redirecting { :location => @redirecting, } else { } end end |
#missing_args ⇒ Object
172 173 174 |
# File 'app/models/fabulator_page.rb', line 172 def missing_args @sm_missing_args end |
#render_snippet(p) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/models/fabulator_page.rb', line 111 def render_snippet(p) if p.name != XML_PART_NAME FabulatorFilter.set_page(self) r = super FabulatorFilter.reset_page r else FabulatorLibrary.all.each do |library| if library.compiled_xml.is_a?(Fabulator::Lib::Lib) library.compiled_xml.register_library end end sm = self.state_machine return '' if sm.nil? # run state machine if POST context = FabulatorContext.find_by_page(self) @resetting_context = false if request.method == :get && params[:reset_context] if !context.new_record? context.destroy end # redirect without the reset_context param? @response.redirect(url,302) @resetting_context = true return end begin sm.context = YAML::load(context.context) if sm.context.empty? sm.init_context(self.fabulator_context) end #sm.context.merge!(self.resource_ln, ['resource'] ) if self.resource_ln if request.method == :post sm.run(params) # save context @sm_missing_args = sm.missing_params @sm_errors = sm.errors context.context = YAML::dump(sm.context) context.save end # save statemachine state # display resulting view rescue Fabulator::FabulatorRequireAuth => e @redirecting = e.to_s rescue => e return "<p>#{e.to_s}</p><pre>" + e.backtrace.join("\n") + "</pre>" end return '' if @redirecting if sm.state != XML_PART_NAME return self.render_part(sm.state) else return 'Error: Fabulator application is not in a displayable state.' end end end |
#response_code ⇒ Object
107 108 109 |
# File 'app/models/fabulator_page.rb', line 107 def response_code @resetting_context ? 302 : ( @redirecting ? 304 : 200 ) end |
#state_machine ⇒ Object
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 |
# File 'app/models/fabulator_page.rb', line 44 def state_machine return @state_machine unless @state_machine.nil? begin FabulatorLibrary.all.each do |library| if library.compiled_xml.is_a?(Fabulator::Lib::Lib) library.compiled_xml.register_library end end compiler = Fabulator::Compiler.new part = self.part(XML_PART_NAME) @state_machine = compiler.compile(part.content) rescue => e Rails.logger.info("Compiling the XML application resulted in the following error: #{e}") self.errors.add(:content, "Compiling the XML application resulted in the following error: #{e}") end return @state_machine if self.compiled_xml.nil? || self.compiled_xml == '' self.c_state_machine = nil else self.c_state_machine = (YAML::load(self.compiled_xml) rescue nil) unless self.c_state_machine end self.c_state_machine end |
#url ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/fabulator_page.rb', line 36 def url u = super if !self.resource_ln.nil? u = u + '/' + self.resource_ln end u end |