require 'active_support/core_ext/module/delegation'
require 'flavour_saver'
require 'hashie/mash'
FS.register_helper :adjust_iframe_height_script do
<<-HTML.strip_heredoc.html_safe
HTML
end
FS.register_helper :download_csv do
<<-HTML.strip_heredoc.html_safe
HTML
end
FS.register_helper :download_json do
json = except(:css_uri).to_json
<<-HTML.strip_heredoc.html_safe
HTML
end
FS.register_helper :download_svg do
<<-HTML.strip_heredoc.html_safe
HTML
end
FS.register_helper :download_image do
<<-HTML.strip_heredoc.html_safe
HTML
end
def init_download_script
<<-HTML.strip_heredoc.html_safe
if (!$("div#stanza_buttons")[0]) {
$('body').append("
");
}
HTML
end
module TogoStanza::Stanza
autoload :ExpressionMap, 'togostanza/stanza/expression_map'
autoload :Grouping, 'togostanza/stanza/grouping'
autoload :Markdown, 'togostanza/stanza/markdown'
autoload :Querying, 'togostanza/stanza/querying'
class Context < Hashie::Mash
def respond_to_missing?(*)
# XXX It looks ugly, but we need use not pre-defined properties
true
end
end
class Base
extend ExpressionMap::Macro
include Querying
include Grouping
define_expression_map :properties
define_expression_map :resources
property :css_uri do |css_uri|
if css_uri
css_uri.split(',')
else
%w(
//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.2.2/css/bootstrap.min.css
//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.min.css
/stanza/assets/stanza.css
)
end
end
class_attribute :root
def self.id
to_s.underscore.sub(/_stanza$/, '')
end
delegate :id, to: 'self.class'
def initialize(params = {})
@params = params
end
attr_reader :params
def context
Context.new(properties.resolve_all_in_parallel(self, params))
end
def resource(name)
resources.resolve(self, name, params)
end
def render
path = File.join(root, 'template.hbs')
Tilt.new(path).render(context)
end
def help
path = File.join(root, 'help.md')
TogoStanza::Markdown.render(File.read(path))
end
def metadata
path = File.join(root, 'metadata.json')
if File.exist?(path)
JSON.load(open(path))
else
nil
end
end
end
end