Sha256: 25c0f571a640d3b8b265ed9a0ba36d90806cea91599bc566861c7411a295bebf

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

require 'happy-helpers'

module Happy
  module ContextExtensions
    module Helpers
      include HappyHelpers::Helpers

      def render(what, options = {}, &blk)
        case what
          when NilClass   then ''
          when String     then render_template(what, options, &blk)
          when Enumerable then what.map { |i| render(i, options, &blk) }.join
          else render_resource(what, options)
        end
      end

      def render_template(name, variables = {}, &blk)
        HappyHelpers::Templates.render(name, self, variables, &blk)
      end

      def render_resource(resource, options = {})
        # build name strings
        singular_name = resource.class.to_s.tableize.singularize
        plural_name   = singular_name.pluralize

        # set options
        options = {
          singular_name => resource
        }.merge(options)

        # render
        render_template("#{plural_name}/_#{singular_name}.html.haml", options)
      end

      alias_method :h, :escape_html
      alias_method :l, :localize
      alias_method :t, :translate
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
happy-0.1.0.pre8 lib/happy/context_ext/helpers.rb
happy-0.1.0.pre7 lib/happy/context_ext/helpers.rb
happy-0.1.0.pre.6 lib/happy/context_ext/helpers.rb
happy-0.1.0.pre.5 lib/happy/context_ext/helpers.rb
happy-0.1.0.pre.4 lib/happy/context_ext/helpers.rb