Class: JekyllSupport::HRefTag

Inherits:
JekyllTag
  • Object
show all
Includes:
Comparable, HashArray, JekyllHrefVersion
Defined in:
lib/href_tag.rb,
lib/href_match.rb,
lib/href_private.rb,
lib/href_summary.rb,
lib/href_page_title.rb

Overview

Implements href Jekyll tag

Constant Summary

Constants included from JekyllHrefVersion

JekyllHrefVersion::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashArray

#add_global_link_for_page, add_global_link_for_page, add_link_for_page, #add_local_link_for_page, add_local_link_for_page, #reset, reset

Instance Attribute Details

#followObject (readonly)

Returns the value of attribute follow.



34
35
36
# File 'lib/href_tag.rb', line 34

def follow
  @follow
end

#helperObject (readonly)

Returns the value of attribute helper.



34
35
36
# File 'lib/href_tag.rb', line 34

def helper
  @helper
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



34
35
36
# File 'lib/href_tag.rb', line 34

def line_number
  @line_number
end

Returns the value of attribute link.



36
37
38
# File 'lib/href_tag.rb', line 36

def link
  @link
end

Returns the value of attribute link_save.



34
35
36
# File 'lib/href_tag.rb', line 34

def link_save
  @link_save
end

#matchObject (readonly)

Returns the value of attribute match.



34
35
36
# File 'lib/href_tag.rb', line 34

def match
  @match
end

#pageObject (readonly)

Returns the value of attribute page.



34
35
36
# File 'lib/href_tag.rb', line 34

def page
  @page
end

#pathObject (readonly)

Returns the value of attribute path.



34
35
36
# File 'lib/href_tag.rb', line 34

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



34
35
36
# File 'lib/href_tag.rb', line 34

def site
  @site
end

#summaryObject (readonly)

Returns the value of attribute summary.



34
35
36
# File 'lib/href_tag.rb', line 34

def summary
  @summary
end

#summary_excludeObject (readonly)

Returns the value of attribute summary_exclude.



34
35
36
# File 'lib/href_tag.rb', line 34

def summary_exclude
  @summary_exclude
end

#summary_hrefObject (readonly)

Returns the value of attribute summary_href.



34
35
36
# File 'lib/href_tag.rb', line 34

def summary_href
  @summary_href
end

#targetObject (readonly)

Returns the value of attribute target.



34
35
36
# File 'lib/href_tag.rb', line 34

def target
  @target
end

#textObject (readonly)

Returns the value of attribute text.



34
35
36
# File 'lib/href_tag.rb', line 34

def text
  @text
end

#urlObject (readonly)

Returns the value of attribute url.



34
35
36
# File 'lib/href_tag.rb', line 34

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object



64
65
66
67
68
# File 'lib/href_tag.rb', line 64

def <=>(other)
  return nil unless other.is_a?(self.class)

  [follow, match, path, target, text] <=> [other.follow, other.match, other.path, other.target, other.text]
end

#==(other) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/href_tag.rb', line 42

def ==(other)
  case other
  when self.class
    follow == other.follow &&
      match == other.match &&
      path == other.path &&
      target == other.target &&
      text == other.text
  when MiniHref
    follow == other.follow &&
      text == other.html &&
      link == other.link &&
      line_number == other.line_number &&
      link_save == other.link_save &&
      path == other.path &&
      summary_exclude == other.summary_exclude &&
      summary_href == other.summary_href
  else
    false
  end
end

#inspectObject



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/href_tag.rb', line 129

def inspect
  # "On line #{line_number} of #{path}:"
  msg = '<HRef'
  msg += follow unless follow.empty?
  msg += " match='#{match}'" if match
  msg += " path='#{path}'" # if path
  msg += target unless target.empty?
  msg += " link='#{link}'" # unless link.empty?
  msg += " text='#{text[0..20]}#{text.length > 20 ? "'..." : "'"}" unless text.empty?
  msg += '>'
  msg
end

#render_implString

Method prescribed by the Jekyll plugin lifecycle.

Parameters:

  • liquid_context (Liquid::Context)

Returns:

  • (String)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/href_tag.rb', line 73

def render_impl
  globals_initial
  linkk, error_msg = compute_linkk
  return error_msg unless linkk

  linkk.delete_prefix './' # normalize relative links
  @url = linkk if @url
  @link_save = linkk

  @helper_save = @helper.clone
  globals_update(@helper.argv, linkk) # Sets @link and @text, might clear @follow and @target
  handle_match(linkk) if @match # Sets @text if not set by now, also @link_type, etc.

  @link.gsub! ' ', '%20'

  raise HrefError, '@link_type was not set' if @link_type == LinkType::UNKNOWN

  save_summary

  klass = " class='#{@klass}'" if @klass
  style = " style='#{@style}'" if @style

  if @link_type == LinkType::LOCAL &&
     @mode == 'production' &&
     @label_source != LabelSource::FROM_IMPLICIT_LABEL &&
     @link != '#'
    path, _fragment = @link.split('#')
    page = ::Jekyll::Draft.page_match path
    if ::Jekyll::Draft.draft? page
      klass = "draft_link #{@klass}".strip
      raise HrefError,
            "<span class='#{klass}'#{style}><span class='draft_title'>#{page.title}</span> <span class='draft_label'>#{@text}</span></span>"
    end
  end

  "<a href='#{@link}'#{klass}#{style}#{@target}#{@follow}>#{@text}</a>"
rescue HrefError => e # jekyll_plugin_support handles StandardError
  @logger.error { JekyllPluginHelper.remove_html_tags e.logger_message }
  exit 1 if @die_on_demo_tag_error

  e.html_message
end

#to_sObject



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/href_tag.rb', line 116

def to_s
  # "On line #{line_number} of #{path}:"
  msg = '<HRef'
  msg += follow unless follow.empty?
  msg += " match='#{match}'" if match
  msg += " path='#{path}'" # if path
  msg += target unless target.empty?
  msg += " link='#{link}'" # unless link.empty?
  msg += " text='#{text}'" unless text.empty?
  msg += '>'
  msg
end