Sha256: e2dfdec27bda78521e3575b67e547fbf3e8f4d9b41303eb10f2846030324d960

Contents?: true

Size: 1.28 KB

Versions: 12

Compression:

Stored size: 1.28 KB

Contents

class Card
  module Set
    module Format
      module AbstractFormat
        # Support haml templates in a Rails like way:
        # If the view option `template: :haml` is set then a haml template is expected
        # in a corresponding template path and renders it.
        #
        # @example
        #   # mod/core/set/type/basic.rb
        #   view :my_view, template: :haml  # uses mod/core/view/type/basic/my_view.haml
        #
        #   view :sample_view, template: :haml do
        #     @actor = "Mark Haml"
        #   end
        #
        #   # mod/core/set/type/basic/sample_view.haml
        #   Luke is played by
        #     = actor
        #
        #   > render :sample_view  # => "Luke is played by Mark Haml"
        module HamlViews
          include Card::Set::Format::HamlPaths

          private

          def haml_view_block view, &block
            path = haml_template_path view
            haml_template_proc ::File.read(path), path, &block
          end

          def haml_template_proc template, path, &block
            proc do
              with_template_path path do
                locals = haml_block_locals(&block)
                haml_to_html template, locals, nil, path: path
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
card-1.108.1 lib/card/set/format/abstract_format/haml_views.rb
card-1.108.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.107.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.106.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.6 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.5 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.4 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.3 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.2.pre1 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.2 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.1 lib/card/set/format/abstract_format/haml_views.rb
card-1.105.0 lib/card/set/format/abstract_format/haml_views.rb