Class: JekyllIndexPages::URLTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-index-pages/tags.rb

Direct Known Subclasses

ArchiveURL, AuthorURL, CategoryURL, TagURL

Constant Summary collapse

STRING_SYNTAX =
%r{^\"[[:alnum:]\- ]+\"$}u
VARIABLE_SYNTAX =
%r{^\(?[[:alnum:]\-\.\[\]]+\)?$}u

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ URLTag

Returns a new instance of URLTag.



6
7
8
9
10
# File 'lib/jekyll-index-pages/tags.rb', line 6

def initialize(tag_name, markup, tokens)
  super
  @markup = markup.strip
  @tag_name = tag_name
end

Instance Method Details

#filter_config(config) ⇒ Object



40
41
42
# File 'lib/jekyll-index-pages/tags.rb', line 40

def filter_config(config)
  nil
end

#has_kind?(site, kind) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/jekyll-index-pages/tags.rb', line 36

def has_kind?(site, kind)
  false
end

#parse_params(context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-index-pages/tags.rb', line 12

def parse_params(context)
  input = ""
  if @markup.match(STRING_SYNTAX)
    input = @markup.gsub("\"", "")
  elsif @markup.match(VARIABLE_SYNTAX)
    input = Liquid::Variable.new(@markup).render(context)
  else
    raise ArgumentError, <<-eos
Invalid syntax for #{@tag_name} tag:

  #{@markup}

Valid syntax:

  {% #{@tag_name} "Name" %}

  or

  {% #{@tag_name} variable %}

eos
  end
end

#render(context) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/jekyll-index-pages/tags.rb', line 44

def render(context)
  site = context.registers[:site]
  master_config = site.config["index_pages"] || {}

  kind = parse_params(context)
  return "" if !has_kind?(site, kind)
  slug =
    I18n.transliterate(
      Jekyll::Utils.slugify(kind),
      :locale => I18n.locale
    )

  config = filter_config(master_config)
  permalink = config ? config["permalink"] : "/:label/"
  permalink.sub(":label", slug)
end