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 module TogoStanza::Stanza autoload :ExpressionMap, 'togostanza/stanza/expression_map' autoload :Grouping, 'togostanza/stanza/grouping' autoload :Markdown, 'togostanza/stanza/markdown' autoload :Querying, 'togostanza/stanza/querying' autoload :TextSearch, 'togostanza/stanza/text_search' 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 include TextSearch 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 /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 end end