Class: Jekyll::AssetsPlugin::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/assets_plugin/renderer.rb

Constant Summary collapse

STYLESHEET =
'<link rel="stylesheet" href="%{path}"%{attrs}>'
JAVASCRIPT =
'<script src="%{path}"%{attrs}></script>'
IMAGE =
'<img src="%{path}"%{attrs}>'
IMAGESIZE =
'width="%d" height="%d"'
URI_RE =
%r{^(?:[^:]+:)?//(?:[^./]+\.)+[^./]+/}
PARAMS_RE =
/ ^
  \s*
  (?: "(?<path>[^"]+)" | '(?<path>[^']+)' | (?<path>[^ ]+) )
  (?<attrs>.*?)
  (?: \[(?<options>.*)\] )?
  \s*
  $
/x

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, params) ⇒ Renderer

Returns a new instance of Renderer.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll/assets_plugin/renderer.rb', line 24

def initialize(context, params)
  @site = context.registers[:site]

  match = params.strip.match PARAMS_RE

  @path     = match["path"]
  @attrs    = match["attrs"].strip
  @options  = match["options"].to_s.split(",")

  @attrs    = " #{@attrs}" unless @attrs.empty?
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



22
23
24
# File 'lib/jekyll/assets_plugin/renderer.rb', line 22

def attrs
  @attrs
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/jekyll/assets_plugin/renderer.rb', line 22

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/jekyll/assets_plugin/renderer.rb', line 22

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



22
23
24
# File 'lib/jekyll/assets_plugin/renderer.rb', line 22

def site
  @site
end

Instance Method Details

#render_assetObject



36
37
38
39
# File 'lib/jekyll/assets_plugin/renderer.rb', line 36

def render_asset
  fail "Can't render remote asset: #{path}" if remote?
  site.assets[path].to_s
end

#render_asset_pathObject



41
42
43
44
# File 'lib/jekyll/assets_plugin/renderer.rb', line 41

def render_asset_path
  return path if remote?
  site.asset_path path
end

#render_imageObject



54
55
56
57
# File 'lib/jekyll/assets_plugin/renderer.rb', line 54

def render_image
  autosize!
  render_tag IMAGE
end

#render_javascriptObject



46
47
48
# File 'lib/jekyll/assets_plugin/renderer.rb', line 46

def render_javascript
  render_tag JAVASCRIPT, ".js"
end

#render_stylesheetObject



50
51
52
# File 'lib/jekyll/assets_plugin/renderer.rb', line 50

def render_stylesheet
  render_tag STYLESHEET, ".css"
end