Class: Bridgetown::PrototypePage
- Inherits:
-
GeneratedPage
- Object
- GeneratedPage
- Bridgetown::PrototypePage
- Defined in:
- lib/bridgetown-core/generators/prototype_generator.rb
Constant Summary
Constants inherited from GeneratedPage
GeneratedPage::HTML_EXTENSIONS
Instance Attribute Summary collapse
Attributes inherited from GeneratedPage
#basename, #content, #data, #dir, #ext, #name, #output, #paginator, #site
Instance Method Summary collapse
-
#initialize(prototyped_page, collection, search_term, term) ⇒ PrototypePage
constructor
A new instance of PrototypePage.
- #process_prototype_page_data(collection, search_term, term) ⇒ Object
-
#process_title_data_placeholder(search_term, term) ⇒ Object
rubocop:todo Metrics/AbcSize.
- #process_title_simple_placeholders(term) ⇒ Object
- #slugify_term(term) ⇒ Object
Methods inherited from GeneratedPage
#[], #converter_output_ext, #converters, #destination, #html?, #index?, #inspect, #layout, #output_ext, #output_exts, #path, #permalink, #permalink_ext, #place_into_layouts, #process, #relative_path, #slots, #template, #to_liquid, #to_s, #transform!, #trigger_hooks, #type, #url, #url_placeholders, #write, #write?
Methods included from Transformable
#transform_content, #transform_with_layout
Methods included from Publishable
Methods included from Localizable
#all_locales, #localeless_path, #matches_resource?
Methods included from LiquidRenderable
#liquid_engine_configured?, #render_with_liquid?, #yaml_file?
Methods included from LayoutPlaceable
#no_layout?, #place_in_layout?
Constructor Details
#initialize(prototyped_page, collection, search_term, term) ⇒ PrototypePage
Returns a new instance of PrototypePage.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 128 def initialize(prototyped_page, collection, search_term, term) # rubocop:disable Lint/MissingSuper @prototyped_page = prototyped_page @site = prototyped_page.site @url = "" @name = "index.html" @ext = ".html" @basename = "index" @dir = Pathname.new(prototyped_page.relative_path).dirname.to_s.sub(%r{^_pages}, "") @path = site.in_source_dir(@dir, @name) self.data = Bridgetown::Utils.deep_merge_hashes prototyped_page.data, {} self.content = prototyped_page.content process_prototype_page_data(collection, search_term, term) Bridgetown::Hooks.trigger :generated_pages, :post_init, self end |
Instance Attribute Details
#prototyped_page ⇒ Bridgetown::GeneratedPage, Bridgetown::Resource::Base (readonly)
122 123 124 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 122 def prototyped_page @prototyped_page end |
Instance Method Details
#process_prototype_page_data(collection, search_term, term) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 146 def process_prototype_page_data(collection, search_term, term) pagination_key = prototyped_page.data.key?("paginate") ? "paginate" : "pagination" # Fill in pagination details to be handled later by Bridgetown::Paginate data["pagination"] = Bridgetown::Utils.deep_merge_hashes( prototyped_page.data[pagination_key].to_h, { "enabled" => true, "collection" => collection, "where_query" => [search_term, term], } ) # Use the original prototype page term so we get "tag" back, not "tags": data[prototyped_page.data["prototype"]["term"]] = term # Process title and slugs/URLs: process_title_data_placeholder(search_term, term) process_title_simple_placeholders(term) slugify_term(term) end |
#process_title_data_placeholder(search_term, term) ⇒ Object
rubocop:todo Metrics/AbcSize
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 164 def process_title_data_placeholder(search_term, term) # rubocop:todo Metrics/AbcSize unless prototyped_page.data["prototype"]["data"] && data["title"]&.include?(":prototype-data-label") return end = site.data[prototyped_page.data["prototype"]["data"]][term] return unless data["#{search_term}_data"] = data_label = [prototyped_page.data["prototype"]["data_label"]] data["title"] = data["title"].gsub( ":prototype-data-label", data_label ) end |
#process_title_simple_placeholders(term) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 180 def process_title_simple_placeholders(term) if data["title"]&.include?(":prototype-term-titleize") data["title"] = data["title"].gsub( ":prototype-term-titleize", Bridgetown::Utils.titleize_slug(term) ) end return unless data["title"]&.include?(":prototype-term") data["title"] = data["title"].gsub( ":prototype-term", term ) end |
#slugify_term(term) ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/bridgetown-core/generators/prototype_generator.rb', line 194 def slugify_term(term) term_slug = Bridgetown::Utils.slugify(term, mode: site.config.slugify_mode) @url = if permalink.is_a?(String) data["permalink"] = data["permalink"].sub(":term", term_slug) else "/#{@dir}/#{term_slug}/" end end |