Class: TogoStanza::Stanza::Base
- Inherits:
-
Object
- Object
- TogoStanza::Stanza::Base
- Extended by:
- ExpressionMap::Macro
- Defined in:
- lib/togostanza/stanza/base.rb
Constant Summary
Constants included from Querying
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #context ⇒ Object
-
#initialize(params = {}) ⇒ Base
constructor
A new instance of Base.
- #metadata(server_url) ⇒ Object
- #render ⇒ Object
- #resource(name) ⇒ Object
Methods included from ExpressionMap::Macro
Methods included from Grouping
Methods included from Querying
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
186 187 188 |
# File 'lib/togostanza/stanza/base.rb', line 186 def initialize(params = {}) @params = params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
190 191 192 |
# File 'lib/togostanza/stanza/base.rb', line 190 def params @params end |
Class Method Details
.id ⇒ Object
180 181 182 |
# File 'lib/togostanza/stanza/base.rb', line 180 def self.id to_s.underscore.sub(/_stanza$/, '') end |
Instance Method Details
#context ⇒ Object
192 193 194 |
# File 'lib/togostanza/stanza/base.rb', line 192 def context Hashie::Mash.new(properties.resolve_all_in_parallel(self, params)) end |
#metadata(server_url) ⇒ Object
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/togostanza/stanza/base.rb', line 206 def (server_url) path = File.join(root, 'metadata.json') if File.exist?(path) orig = JSON.load(open(path)) stanza_uri = "#{server_url}/#{orig['id']}" usage_attrs = orig['parameter'].map {|hash| unless hash['key'].start_with?("data-stanza-") then hash['key'] = "data-stanza-" << hash['key'] end "#{hash['key']}=\"#{hash['example']}\"" }.push("data-stanza=\"#{stanza_uri}\"").join(' ') append_prefix_to_hash_keys(orig.merge(usage: "<div #{usage_attrs}></div>"), 'stanza').merge('@id' => stanza_uri) else nil end end |
#render ⇒ Object
200 201 202 203 204 |
# File 'lib/togostanza/stanza/base.rb', line 200 def render path = File.join(root, 'template.hbs') Tilt.new(path).render(context) end |
#resource(name) ⇒ Object
196 197 198 |
# File 'lib/togostanza/stanza/base.rb', line 196 def resource(name) resources.resolve(self, name, params) end |