Sha256: 68be7f574e7c675417c824bca4888a58cf745ddf3dc714d4c49f2d5406824e6b

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# A Liquid Tag for retrieving path information for theme specific media
#
# Returns the path based on the file extension
#
class Themeitem < Liquid::Block

   @@image_exts = %w( .png .jpg .jpeg .jpe .gif )

   @@stylesheet_exts = %w( .css )

   @@javascript_exts = %w( .js .htc )
                                      
   def initialize(markup, tokens)
      super
      #@media_type = markup.strip
   end

   def block_delimiter
     ["endthemeitem"]
   end                           
   
   def block_name
     "themeitem"
   end

   def render(context)
      # Which, if either, of these are correct?
      base_url = context['request'].relative_url_root || ActionController::Base.asset_host.to_s

      filename = @nodelist.join('').strip
      ext = File.extname( filename )

      if @@image_exts.include?( ext )
         "#{base_url}/themes/#{context['active_theme']}/images/#{filename}"

      elsif @@stylesheet_exts.include?( ext )
         "#{base_url}/themes/#{context['active_theme']}/stylesheets/#{filename}"
         
      elsif @@javascript_exts.include?( ext )
         "#{base_url}/themes/#{context['active_theme']}/javascripts/#{filename}"
      end
   end   
end

Liquid::Template.register_block( 'themeitem', Themeitem )

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme_generator-1.2.1 templates/liquid_helpers.rb
theme_generator-1.2.2 templates/liquid_helpers.rb
theme_generator-1.2.0 templates/liquid_helpers.rb