Sha256: fbf50d7248a1c61576065b2fce9a73c7366aedc646827b12e8eeb1a61ec21f27

Contents?: true

Size: 924 Bytes

Versions: 9

Compression:

Stored size: 924 Bytes

Contents

module StaticMatic
  module Helpers
    module TagHelper
      self.extend self
      
      # Generates HTML tags:
      #
      # tag(:br)   ->   <br/>
      # tag(:a, :href => 'test.html') { "Test" }    ->    <a href="test.html">Test</a>
      #
      def tag(name, options = {}, &block)
        options[:id] ||= options[:name] if options[:name]
        output = "<#{name}"
        options.keys.sort { |a, b| a.to_s <=> b.to_s }.each do |key|
          output << " #{key}=\"#{options[key]}\"" if options[key]
        end
        
        if block_given?
          output << ">"
          output << yield
          output << "</#{name}>"
        else
          format = @staticmatic.configuration.engine_options['haml'][:format]
          
          if format.nil? || format == :xhtml
            output << "/>"
          else
            output << ">"
          end
        end
        output
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
staticmatic2-2.1.8 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.7 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.6 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.5 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.4 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.3 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.2 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.1 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.1.0 lib/staticmatic/helpers/tag_helper.rb