Sha256: ea1bd4f9ea175c5164b848e8983dea8f89b7f48d03a1d274df1f16ee43399777

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

require 'happy-helpers'

module Happy
  module Helpers
    include HappyHelpers::Helpers

    def render(what, options = {}, &blk)
      case what
        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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
happy-0.1.0.pre.1 lib/happy/helpers.rb