Sha256: 6e4cd54599f020da87ab0ab6f65da846b9c7c34427673325c65da2b8e0cf69dd

Contents?: true

Size: 1.7 KB

Versions: 30

Compression:

Stored size: 1.7 KB

Contents

module Alula
  module Helpers
    def stylesheet_link(name = "style", opts = {})
      name += ".css" if File.extname(name).empty?
      options = opts.collect{|name,value| !!value == value ? (value ? "#{name}" : "") : "#{name}=\"#{value}\"" }.join(" ")
      
      if asset_url(name)
        # Inline?
        if self.environment[name].pathname.size > 10
          "<link rel=\"stylesheet\" href=\"#{asset_url(name)}\" type=\"text/css\" #{options}/>"
        else
          content = self.environment[name].pathname.read
          "<style type=\"text/css\" #{options}>#{content}</style>"
        end
      end
    end
    
    def javascript_link(name = "script", opts = {})
      name += ".js" if File.extname(name).empty?
      case Alula::Plugin.script_load_mode
      when :async
        opts[:async] = true
      when :defer
        opts[:defer] = true
      end
      options = opts.collect{|name,value| !!value == value ? (value ? "#{name}" : "") : "#{name}=\"#{value}\"" }.join(" ")
      
      if asset_url(name)
        # Inline?
        if self.environment[name].pathname.size > 10
          "<script #{options} src=\"#{asset_url(name)}\"></script>"
        else
          content = self.environment[name].pathname.read
          "<script #{options}>#{content}</script>"
        end
      end      
    end
    
    def asset_path(name)
      return if name.nil?

      if self.environment[name]
        # Get asset URL
        asset_path = File.join("assets", self.environment[name].digest_path)
      end
    end
    
    def asset_url(name)
      return if name.nil?

      if self.environment[name]
        self.site.cdn.url_for(asset_path(name), file: self.environment[name].pathname.to_s)
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
alula-0.4.27 lib/alula/helpers/assets.rb
alula-0.4.26 lib/alula/helpers/assets.rb
alula-0.4.25 lib/alula/helpers/assets.rb
alula-0.4.24 lib/alula/helpers/assets.rb
alula-0.4.23 lib/alula/helpers/assets.rb
alula-0.4.22 lib/alula/helpers/assets.rb
alula-0.4.21 lib/alula/helpers/assets.rb
alula-0.4.20 lib/alula/helpers/assets.rb
alula-0.4.19 lib/alula/helpers/assets.rb
alula-0.4.18 lib/alula/helpers/assets.rb
alula-0.4.17 lib/alula/helpers/assets.rb
alula-0.4.16 lib/alula/helpers/assets.rb
alula-0.4.15 lib/alula/helpers/assets.rb
alula-0.4.14 lib/alula/helpers/assets.rb
alula-0.4.13 lib/alula/helpers/assets.rb
alula-0.4.12 lib/alula/helpers/assets.rb
alula-0.4.11 lib/alula/helpers/assets.rb
alula-0.4.11a lib/alula/helpers/assets.rb
alula-0.4.10 lib/alula/helpers/assets.rb
alula-0.4.9 lib/alula/helpers/assets.rb