class TogoStanza::Stanza::Base
Attributes
params[R]
Public Class Methods
id()
click to toggle source
# File lib/togostanza/stanza/base.rb, line 180 def self.id to_s.underscore.sub(/_stanza$/, '') end
new(params = {})
click to toggle source
# File lib/togostanza/stanza/base.rb, line 186 def initialize(params = {}) @params = params end
Public Instance Methods
context()
click to toggle source
# File lib/togostanza/stanza/base.rb, line 192 def context Hashie::Mash.new(properties.resolve_all_in_parallel(self, params)) end
metadata(server_url)
click to toggle source
# File lib/togostanza/stanza/base.rb, line 206 def metadata(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()
click to toggle source
# File lib/togostanza/stanza/base.rb, line 200 def render path = File.join(root, 'template.hbs') Tilt.new(path).render(context) end
resource(name)
click to toggle source
# File lib/togostanza/stanza/base.rb, line 196 def resource(name) resources.resolve(self, name, params) end
Private Instance Methods
append_prefix_to_hash_keys(hash, prefix)
click to toggle source
# File lib/togostanza/stanza/base.rb, line 228 def append_prefix_to_hash_keys(hash, prefix) hash.each_with_object({}) do |(key, value), new_hash| new_hash["#{prefix}:#{key}"] = expand_values(value, prefix) end end
expand_values(value, prefix)
click to toggle source
# File lib/togostanza/stanza/base.rb, line 234 def expand_values(value, prefix) case value when Hash append_prefix_to_hash_keys(value, prefix) when Array value.map {|v| expand_values(v, prefix) } else value end end