Sha256: cb163b16694d210aa158a68fdd8cb419d25df52611f3b26f8fe937d3bc83c93c

Contents?: true

Size: 1.29 KB

Versions: 12

Compression:

Stored size: 1.29 KB

Contents

module Locomotive
  module Steam
    module Liquid
      module Tags
        module Editable
          class File < Base

            protected

            def default_element_attributes
              super.merge({
                default_source_url: render_default_content.strip
              })
            end

            def render_element(context, element)
              default_timestamp = context.registers[:page].updated_at.to_i

              url, timestamp = (if element.source
                [source_url(element), default_timestamp]
              else
                if element.default_source_url.present?
                  [element.default_source_url, default_timestamp]
                else
                  [render_default_content, nil]
                end
              end)

              context.registers[:services].asset_host.compute(url, timestamp)
            end

            def source_url(element)
              if element.source =~ /^https?/
                element.source
              else
                _url = element.source.start_with?('/') ? element.source : "/#{element.source}"
                "#{element.base_url}#{_url}"
              end
            end

          end

          ::Liquid::Template.register_tag('editable_file'.freeze, File)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.rc9 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc6 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc4 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/liquid/tags/editable/file.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/liquid/tags/editable/file.rb