Sha256: d5cecbd705d11b50925dac933e07ff9b8fda0e80a58cf4ffccc3da086db77cf5

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 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 :Markdown,      'togostanza/stanza/markdown'
  autoload :Querying,      'togostanza/stanza/querying'

  class Base
    extend ExpressionMap::Macro
    include Querying

    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
      Hashie::Mash.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

6 entries across 6 versions & 1 rubygems

Version Path
togostanza-0.0.6 lib/togostanza/stanza/base.rb
togostanza-0.0.5 lib/togostanza/stanza/base.rb
togostanza-0.0.4 lib/togostanza/stanza/base.rb
togostanza-0.0.3 lib/togostanza/stanza/base.rb
togostanza-0.0.2 lib/togostanza/stanza/base.rb
togostanza-0.0.1 lib/togostanza/stanza/base.rb