module Locomotive module Liquid module Filters module Html # Write the link to a stylesheet resource # input: url of the css file def stylesheet_tag(input) return '' if input.nil? unless input =~ /^(\/|http:)/ input = asset_url("stylesheets/#{input}") end input = "#{input}.css" unless input.ends_with?('.css') %{} end # Write the link to javascript resource # input: url of the javascript file def javascript_tag(input) return '' if input.nil? unless input =~ /^(\/|http:)/ input = asset_url("javascripts/#{input}") end input = "#{input}.js" unless input.ends_with?('.js') %{} end def theme_image_url(input) return '' if input.nil? input = "images/#{input}" unless input.starts_with?('/') asset_url(input) end # Write a theme image tag # input: name of file including folder # example: 'about/myphoto.jpg' | theme_image # def theme_image_tag(input, *args) return '' if input.nil? input = "images/#{input}" unless input.starts_with?('/') image_options = inline_options(args_to_options(args)) "" end # Write an image tag # input: url of the image OR asset drop def image_tag(input, *args) image_options = inline_options(args_to_options(args)) "" end # Embed a flash movie into a page # input: url of the flash movie OR asset drop # width: width (in pixel or in %) of the embedded movie # height: height (in pixel or in %) of the embedded movie def flash_tag(input, *args) path = get_url_from_asset(input) embed_options = inline_options(args_to_options(args)) %{ }.gsub(/ >/, '>').strip end # Render the navigation for a paginated collection def default_pagination(paginate, *args) return '' if paginate['parts'].empty? options = args_to_options(args) previous_label = options[:previous_label] || I18n.t('pagination.previous') next_label = options[:next_label] || I18n.t('pagination.next') previous_link = (if paginate['previous'].blank? "#{previous_label}" else "#{previous_label}" end) links = "" paginate['parts'].each do |part| links << (if part['is_link'] "#{part['title']}" elsif part['hellip_break'] "#{part['title']}" else "#{part['title']}" end) end next_link = (if paginate['next'].blank? "#{next_label}" else "#{next_label}" end) %{} end protected # Convert an array of properties ('key:value') into a hash # Ex: ['width:50', 'height:100'] => { :width => '50', :height => '100' } def args_to_options(*args) options = {} args.flatten.each do |a| if (a =~ /^(.*):(.*)$/) options[$1.to_sym] = $2 end end options end # Write options (Hash) into a string according to the following pattern: # ="", ="