Class: SwedbankPay::SidebarPage
- Inherits:
-
Object
- Object
- SwedbankPay::SidebarPage
- Defined in:
- lib/sidebar_page.rb
Overview
Represents a jekyll_page in the Sidebar
Constant Summary collapse
- FIXNUM_MAX =
((2**((0.size * 8) - 2)) - 1)
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
Returns the value of attribute number.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#sidebar_container ⇒ Object
Returns the value of attribute sidebar_container.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #active?(current, is_leaf: false) ⇒ Boolean
- #anchor_headings? ⇒ Boolean
- #card_overview? ⇒ Boolean
- #children? ⇒ Boolean
- #coordinate ⇒ Object
- #enrich_jekyll ⇒ Object
- #headers? ⇒ Boolean
- #hidden? ⇒ Boolean
- #hidden_for?(other_page) ⇒ Boolean
-
#initialize(jekyll_page) ⇒ SidebarPage
constructor
A new instance of SidebarPage.
- #inspect ⇒ Object
- #load ⇒ Object
- #save ⇒ Object
- #to_liquid ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(jekyll_page) ⇒ SidebarPage
Returns a new instance of SidebarPage.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sidebar_page.rb', line 19 def initialize(jekyll_page) raise ArgumentError, 'jekyll_page cannot be nil' if jekyll_page.nil? raise ArgumentError, 'jekyll_page must be a Jekyll::Page' unless jekyll_page.is_a? Jekyll::Page @filename = jekyll_page.destination('') @jekyll_page = jekyll_page = SidebarPath.new(jekyll_page['url']) @path = .to_s @parent = .parent @level = .level @hide_from_sidebar = jekyll_page['hide_from_sidebar'].nil? ? false : jekyll_page['hide_from_sidebar'] @title = SidebarPageTitle.parse(jekyll_page, self) @order = (jekyll_page) @section = jekyll_page['section'] @icon = jekyll_page['sidebar_icon'] @children = SidebarPageCollection.new(self) @card_overview = jekyll_page['card_overview'].nil? ? false : jekyll_page['card_overview'] @anchor_headings = jekyll_page['anchor_headings'].nil? ? true : jekyll_page['anchor_headings'] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def children @children end |
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def doc @doc end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def filename @filename end |
#headers ⇒ Object
Returns the value of attribute headers.
17 18 19 |
# File 'lib/sidebar_page.rb', line 17 def headers @headers end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def icon @icon end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def name @name end |
#number ⇒ Object
Returns the value of attribute number.
17 18 19 |
# File 'lib/sidebar_page.rb', line 17 def number @number end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def order @order end |
#parent ⇒ Object
Returns the value of attribute parent.
17 18 19 |
# File 'lib/sidebar_page.rb', line 17 def parent @parent end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def path @path end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def section @section end |
#sidebar_container ⇒ Object
Returns the value of attribute sidebar_container.
17 18 19 |
# File 'lib/sidebar_page.rb', line 17 def @sidebar_container end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
16 17 18 |
# File 'lib/sidebar_page.rb', line 16 def title @title end |
Instance Method Details
#<=>(other) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sidebar_page.rb', line 96 def <=>(other) return -1 if other.nil? if @order == FIXNUM_MAX && other.order == FIXNUM_MAX return 0 if @title.nil? && other.title.nil? return -1 if other.title.nil? return 1 if title.nil? return @title <=> other.title end @order <=> other.order end |
#active?(current, is_leaf: false) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sidebar_page.rb', line 39 def active?(current, is_leaf: false) current_path = find_path(current) return true if @path == current_path # If we're on a leaf node item, such as when rendering the first header # item of a sub-group, its children's active state must be disregarded. unless is_leaf @children.each do |child| return true if child.active?(current_path, is_leaf: is_leaf) end end false end |
#anchor_headings? ⇒ Boolean
161 162 163 |
# File 'lib/sidebar_page.rb', line 161 def anchor_headings? @anchor_headings end |
#card_overview? ⇒ Boolean
157 158 159 |
# File 'lib/sidebar_page.rb', line 157 def card_overview? @card_overview end |
#children? ⇒ Boolean
133 134 135 |
# File 'lib/sidebar_page.rb', line 133 def children? !children.nil? && children.any? end |
#coordinate ⇒ Object
141 142 143 144 145 146 |
# File 'lib/sidebar_page.rb', line 141 def coordinate return @number.to_s if @parent.nil? return @number.to_s unless @parent.respond_to? :coordinate "#{@parent.coordinate}.#{@number}" end |
#enrich_jekyll ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/sidebar_page.rb', line 110 def enrich_jekyll if @title.nil? SidebarLogger.debug("No title for #{@name}") return end SidebarLogger.debug("<#{@path}>.lead_title('#{@title.lead}').main_title('#{@title.main}')") @jekyll_page.data['lead_title'] = @title.lead @jekyll_page.data['main_title'] = @title.main @jekyll_page.data['children'] = @children @jekyll_page.data['absolute_path'] = @path end |
#headers? ⇒ Boolean
137 138 139 |
# File 'lib/sidebar_page.rb', line 137 def headers? !headers.nil? && headers.any? end |
#hidden? ⇒ Boolean
55 56 57 58 59 60 |
# File 'lib/sidebar_page.rb', line 55 def hidden? return true if @title.nil? return true if @hide_from_sidebar false end |
#hidden_for?(other_page) ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sidebar_page.rb', line 62 def hidden_for?(other_page) if @jekyll_page.data['layout'] == 'search' # Never show the search result page in the menu. return true end # The current page should be hidden for the other page unless the # other page is also hidden. hidden = hidden? if other_page.nil? || !other_page.is_a?(SidebarPage) SidebarLogger.debug("Other page '#{other_page}' is nil or not a SidebarPage") return hidden end # If the other page is hidden, the current page should not be hidden # from it. return false if other_page.hidden? && in_same_section_as?(other_page) hidden end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/sidebar_page.rb', line 92 def inspect to_s end |
#load ⇒ Object
148 149 150 151 |
# File 'lib/sidebar_page.rb', line 148 def load @doc = File.open(@filename) { |f| Nokogiri::HTML(f) } @doc end |
#save ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/sidebar_page.rb', line 124 def save SidebarLogger.debug(" Writing Sidebar: #{filename}") File.open(@filename, 'w') do |file| html = @doc.to_html(encoding: 'UTF-8') file.write(html) end end |
#to_liquid ⇒ Object
153 154 155 |
# File 'lib/sidebar_page.rb', line 153 def to_liquid @jekyll_page.to_liquid end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/sidebar_page.rb', line 88 def to_s SidebarTextBuilder.new(self).to_s end |