Sha256: f3c9fa0f8e5d994d0344083027b5a3cbe25d17da0de00eaa87be9dde36c18f49

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

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
    <script>$(function() {
      height = this.body.offsetHeight + 30;
      parent.postMessage(JSON.stringify({height: height, id: name}), "*");
    });</script>
  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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
togostanza-1.1.0 lib/togostanza/stanza/base.rb