Class: Themeitem

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/theme_support/helpers/liquid_theme_tags.rb

Overview

A Liquid Tag for retrieving path information for theme specific media

Returns the path based on the file extension

Constant Summary collapse

@@image_exts =
%w( .png .jpg .jpeg .jpe .gif )
@@stylesheet_exts =
%w( .css )
@@javascript_exts =
%w( .js .htc )

Instance Method Summary collapse

Instance Method Details

#render(context) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/theme_support/helpers/liquid_theme_tags.rb', line 11

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

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

   if @@image_exts.include?( ext )
      "#{base_url}/themes/#{theme_name}/images/#{filename}"

   elsif @@stylesheet_exts.include?( ext )
      "#{base_url}/themes/#{theme_name}/stylesheets/#{filename}"
      
   elsif @@javascript_exts.include?( ext )
      "#{base_url}/themes/#{theme_name}/javascripts/#{filename}"
   end
end