Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ERB and Beyond docs to ERB and use capture helper for liquid_render #174

Merged
merged 3 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ Lint/Void:
Exclude:
- bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb
Metrics/AbcSize:
Max: 21
Max: 24
Exclude:
- bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb
- bridgetown-core/lib/bridgetown-core/commands/build.rb
- bridgetown-core/lib/bridgetown-core/commands/new.rb
- bridgetown-core/lib/bridgetown-core/commands/console.rb
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-builder/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AllCops:

Metrics/AbcSize:
Exclude:
- lib/bridgetown-builder/dsl/*
- lib/bridgetown-builder/dsl/generators.rb
Metrics/MethodLength:
Exclude:
- lib/bridgetown-builder/dsl/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def process
print_stats if config["profile"]
end

# rubocop:disable Metrics/AbcSize

# Reset all in-memory data and content.
# @return [void]
def reset
Expand Down Expand Up @@ -49,8 +47,6 @@ def reset
Bridgetown::Hooks.trigger :site, :after_reset, self
end

# rubocop:enable Metrics/AbcSize

# Read data from disk and load it into internal memory.
# @return [void]
def read
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def site_drop
site.site_payload.site
end

def liquid_render(component, options = {})
options[:_block_content] = yield if block_given?
def liquid_render(component, options = {}, &block)
options[:_block_content] = capture(&block) if block && respond_to?(:capture)
render_statement = _render_statement(component, options)

template = site.liquid_renderer.file(
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/tags/render_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Bridgetown
module Tags
class BlockRenderTag < Liquid::Block
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# rubocop:disable Metrics/MethodLength
def render(context)
context.stack({}) do
# unindent the incoming text
Expand Down Expand Up @@ -37,7 +37,7 @@ def render(context)
.render_tag(context, +"")
end
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
# rubocop:enable Metrics/MethodLength

private

Expand Down
7 changes: 0 additions & 7 deletions bridgetown-paginate/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ Bridgetown/NoPutsAllowed:
Layout/CommentIndentation:
Exclude:
- lib/bridgetown-paginate/defaults.rb
Metrics/AbcSize:
Exclude:
- lib/bridgetown-paginate/pagination_generator.rb
- lib/bridgetown-paginate/pagination_indexer.rb
- lib/bridgetown-paginate/pagination_model.rb
- lib/bridgetown-paginate/pagination_page.rb
- lib/bridgetown-paginate/paginator.rb
Metrics/BlockNesting:
Exclude:
- lib/bridgetown-paginate/pagination_model.rb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class << self
# site - The Site.
#
# Returns nothing.
def generate(site)
def generate(site) # rubocop:todo Metrics/AbcSize
# Retrieve and merge the pagination configuration from the site yml file
default_config = Bridgetown::Utils.deep_merge_hashes(
DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class << self
# Create a hash index for all documents based on a key in the
# document.data table
#
def self.index_documents_by(all_documents, index_key)
def self.index_documents_by(all_documents, index_key) # rubocop:todo Metrics/AbcSize
return nil if all_documents.nil?
return all_documents if index_key.nil?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def initialize(
end

# rubocop:disable Metrics/BlockLength
def run(default_config, templates, site_title)
def run(default_config, templates, site_title) # rubocop:todo Metrics/AbcSize
if templates.size.to_i <= 0
@logging_lambda.call "is enabled in the config, but no paginated pages found." \
" Add 'pagination:\\n enabled: true' to the front-matter of a page.", "warn"
Expand Down Expand Up @@ -142,7 +142,7 @@ def get_docs_in_collections(raw_collection_names)
end

# rubocop:disable Layout/LineLength
def _debug_print_config_info(config, page_path)
def _debug_print_config_info(config, page_path) # rubocop:todo Metrics/AbcSize
r = 20
f = "Pagination: ".rjust(20)
# Debug print the config
Expand Down Expand Up @@ -185,6 +185,7 @@ def _debug_print_filtering_info(filter_name, before_count, after_count)
# template - The index.html Page that requires pagination.
# config - The configuration settings that should be used
#
# rubocop:todo Metrics/AbcSize
def paginate(template, config, site_title, documents_payload)
# By default paginate on all posts in the site
using_posts = documents_payload[:posts]
Expand Down Expand Up @@ -446,6 +447,7 @@ def paginate(template, config, site_title, documents_payload)
end
end
end
# rubocop:enable Metrics/AbcSize
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Paginate
# not read from disk
#
class PaginationPage < Bridgetown::Page
# rubocop:todo Metrics/AbcSize
def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, template_ext)
@site = page_to_copy.site
@base = ""
Expand Down Expand Up @@ -44,6 +45,7 @@ def initialize(page_to_copy, cur_page_nr, total_pages, index_pageandext, templat

Bridgetown::Hooks.trigger :pages, :post_init, self
end
# rubocop:enable Metrics/AbcSize

# rubocop:disable Naming/AccessorMethodName
def set_url(url_value)
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-paginate/lib/bridgetown-paginate/paginator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Paginator

# Initialize a new Paginator.
#
def initialize(
def initialize( # rubocop:todo Metrics/AbcSize
config_per_page,
first_index_page_url,
paginated_page_url,
Expand Down
19 changes: 11 additions & 8 deletions bridgetown-website/plugins/builders/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

class TagsBuilder < SiteBuilder
def build
liquid_tag "toc" do
<<~TAG
## Table of Contents
{:.no_toc}
* …
{:toc}
TAG
end
liquid_tag "toc", :toc_template
helper "toc", :toc_template
end

def toc_template(attributes=nil, tag=nil)
<<~TAG
## Table of Contents
{:.no_toc}
* …
{:toc}
TAG
end
end
Loading