Module: Alula::Helpers

Defined in:
lib/alula/helpers/addons.rb,
lib/alula/helpers/assets.rb,
lib/alula/helpers/url_helpers.rb

Instance Method Summary collapse

Instance Method Details

#addons(type) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/alula/helpers/addons.rb', line 3

def addons(type)
  content = ""
  Alula::Plugin.addons[type].each do |addon|
    content += addon.respond_to?(:call) ? addon.call(self).to_s : addon
  end
  
  content
end

#asset_path(name) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/alula/helpers/assets.rb', line 39

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

#asset_url(name) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/alula/helpers/assets.rb', line 48

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


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/alula/helpers/assets.rb', line 18

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


7
8
9
10
11
12
13
14
# File 'lib/alula/helpers/url_helpers.rb', line 7

def link_to(content, url, attributes = {})
  tag = "<a"
  tag += " href=\"#{url}\""
  attributes.each do |name, value|
    tag += " #{name}=\"#{value}\""
  end
  tag += ">#{content}</a>"
end


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/alula/helpers/assets.rb', line 3

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

#url_for(name) ⇒ Object



3
4
5
# File 'lib/alula/helpers/url_helpers.rb', line 3

def url_for(name)
  File.join(self.site.config.url, name)
end