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:)/ segments = "stylesheets/#{input}".split('/') filename, folder = segments.pop, segments.join('/') input = asset_url(folder, filename) 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:)/ segments = "javascripts/#{input}".split('/') filename, folder = segments.pop, segments.join('/') input = asset_url(folder, filename) # javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => folder) # # input = '/' + ThemeAssetUploader.new(javascript).store_path(filename) 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?('/') segments = input.split('/') filename, folder = segments.pop, segments.join('/') asset_url(folder, filename) 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_link = (if paginate['previous'].blank? "#{I18n.t('pagination.previous')}" else "#{I18n.t('pagination.previous')}" 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? "#{I18n.t('pagination.next')}" else "#{I18n.t('pagination.next')}" 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: # ="", =" @context.registers[:site], :folder => folder) uploader = ThemeAssetUploader.new(asset) uploader.retrieve_from_store!(filename) uploader.url end end ::Liquid::Template.register_filter(Html) end end end