Sha256: 2e656f23849455f280f9cb3448ce8fcd71a9debf969f0a9cb88a96d350be7672

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 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 :with_instance_variables, template: :haml do
        #     @actor = "Mark Haml"
        #   end
        #
        #   # mod/core/view/type/basic/with_instance_variables.haml
        #   Luke is played by
        #     = actor
        #
        #   > render :with_instance_variables  # => "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

29 entries across 29 versions & 1 rubygems

Version Path
card-1.104.2 lib/card/set/format/abstract_format/haml_views.rb
card-1.104.1 lib/card/set/format/abstract_format/haml_views.rb
card-1.104.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.103.4 lib/card/set/format/abstract_format/haml_views.rb
card-1.103.3 lib/card/set/format/abstract_format/haml_views.rb
card-1.103.2 lib/card/set/format/abstract_format/haml_views.rb
card-1.103.1 lib/card/set/format/abstract_format/haml_views.rb
card-1.103.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.7 lib/card/set/format/abstract_format/haml_views.rb
card-1.102.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.6 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.5 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.4 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.3 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.2 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.1 lib/card/set/format/abstract_format/haml_views.rb
card-1.101.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.100.0 lib/card/set/format/abstract_format/haml_views.rb
card-1.99.6 lib/card/set/format/abstract_format/haml_views.rb
card-1.99.5 lib/card/set/format/abstract_format/haml_views.rb