Sha256: 8c19210921ce1c95ad517c7746f8942401305c915cbfa4fb8221259b20b891ce

Contents?: true

Size: 914 Bytes

Versions: 7

Compression:

Stored size: 914 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.haml_options[:format]
          
          if format.nil? || format == :xhtml
            output << "/>"
          else
            output << ">"
          end
        end
        output
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
staticmatic2-2.0.2 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.0.1 lib/staticmatic/helpers/tag_helper.rb
staticmatic2-2.0.0 lib/staticmatic/helpers/tag_helper.rb
staticmatic-0.11.1 lib/staticmatic/helpers/tag_helper.rb
staticmatic-0.11.0 lib/staticmatic/helpers/tag_helper.rb
staticmatic-0.11.0.alpha.10 lib/staticmatic/helpers/tag_helper.rb
staticmatic-0.11.0.alpha.9 lib/staticmatic/helpers/tag_helper.rb