Skip to content

Commit

Permalink
v0.21 integration branch (#287)
Browse files Browse the repository at this point in the history
* Welcome to 0.21 "Broughton Beach"

* Highlight Render as a hosting provider

* Relations for resources (belongs_to, has_many, etc.) (#261)

* Relations for resources (belongs_to, has_many, etc)

* improve resource type comments

* Make relations available to Liquid templates

* remove stray p methods

* Add test for resource relationships

* Support pluralized belongs_to keys

* make cop happy

* Use model origin id for resource id

* Add documentation and Liquid test for resource relations

* use newer feed gem

* Use list for relation accessor examples

* Fix nil bug in relations schema

* New `Bridgetown::Component` class with a ViewComponent-ish API (#268)

* New Component class with a ViewComponent-ish API

* Isolate site in components and improve link helpers

* Remove unnecessary special render case for ViewComponent

* Fix missing variables

* Relocate markdownify to Helpers class

* Switch to new Rails-like OutputBuffer, more VC support

* Support clean render interop between builtin Component and VCs

* Add several common Liquid filters in as Ruby helpers

Also add output_safety dependency

* Additional html_safe usage

* Match Rails' capture escaping logic

* Change before_render behavior to match latest VC

* Add tests and code comments for Bridgetown::Component

* Couple of YARD updates

* fix cop offense

* Fix bug with url_for helper

* Correct failing ERB feature test

* Use new SEO and feed helpers for the website

* Fix odd cop errors

* Convert website navbar to ERB component

* fix is-active class name

* Use resource variable in default website layout

* Update documentation (WIP) on components subsystem

Also change all occurences of Javascript to JavaScript

* Add lint-html addition

* Add documentation regarding ViewComponent

* Make linthtml happy

* Fix typos

* Add link to components docs from the ERB page

* Add section on ERB output safety to the docs

* End-to-end Ruby front matter, templates, and data files (#285)

* Major feature addition for Ruby Front Matter and raw templates

Also additional work to normalize Liquid & ERB template APIs

* Improve docs

* improve error messages, support Ruby data files

* Add to_json support for Resources

* Improve code quality and test rbfm

* Refactor front matter importing and add rbfm to layouts

* Revert and use regex capture

* Remove logging around rbfm

* Lots of Ruby files and rbfm documentation, couple of fixes

* Better to_json compat

* Fix Liquid error on website build

* Fix erb render bug in docs

* Update Changelog with 0.21 beta details

* Fix dotfiles or multiple extension permalinks (resource engine) (#292)

* Fix bug which was swallowing dotfiles and multiple extensions

* Revert tag refactoring

* Remove sassify/scssify filters, html_safe the obfuscate link

* Refactor old TODOs and deprecations

* Release 0.21 beta 2

* Bugfix for `previous_resource` method

* Ensure resources with no output are still transformed

* Remove a bunch of global config accessors on site

* Switch `plugins new` command to MiniTest in repo

* Release Bridgetown 0.21.0.beta3

* Webiste: use proper metadata title for Index page

* Add I18n file reloader to the watcher process

* Add prototype page warnings of bad configs

* Add note to Resources docs about require prototype page collection key

* Add CLI command to update webpack config (#270)

* Install required packages in webpack enable postcss tool (#319)

* Add config directory and move webpack defaults into it (#316)

* Add confirmation for overwriting postcss config in tailwindcss and bt-postcss bundled configurations (#317)

* Add Bridgetown version to webpack defaults (#322)

* Resolve issue with zombie templates in Pagination/Prototype logic

* Add layout method to resource and label method to layout (#324)

* Add memoization to cache templates in `Bridgetown::Component` (#326)

* Fix the Bridgetown logger and other test improvements (#328)

* Release 0.21.0.beta4

* Release v0.21.0

Co-authored-by: Ayush Newatia <[email protected]>
  • Loading branch information
jaredcwhite and ayushn21 authored Jun 1, 2021
1 parent 34f6c11 commit 9e80e28
Show file tree
Hide file tree
Showing 152 changed files with 2,666 additions and 1,248 deletions.
156 changes: 113 additions & 43 deletions CHANGELOG.md

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions bridgetown-core/features/collections.feature
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ Feature: Collections
When I run bridgetown build
Then I should get a zero exit status
Then the output directory should exist
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html" unless Windows
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/yaml_with_dots.md" in "output/index.html" if on Windows
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html"

Scenario: Collections specified as an hash
Given I have an "index.html" page that contains "Collections: {% for method in site.methods %}{{ method.relative_path }} {% endfor %}"
Expand All @@ -96,8 +95,7 @@ Feature: Collections
When I run bridgetown build
Then I should get a zero exit status
Then the output directory should exist
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html" unless Windows
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/yaml_with_dots.md" in "output/index.html" if on Windows
And I should see "Collections: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html"

Scenario: Rendered collection with document with future date
Given I have a _puppies directory
Expand Down Expand Up @@ -377,8 +375,7 @@ Feature: Collections
When I run bridgetown build
Then I should get a zero exit status
Then the output directory should exist
And I should see "All documents: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html" unless Windows
And I should see "All documents: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/yaml_with_dots.md" in "output/index.html" if on Windows
And I should see "All documents: _methods/3940394-21-9393050-fifif1323-test.md _methods/collection/entries _methods/configuration.md _methods/escape-\+ #%20\[\].md _methods/sanitized_path.md _methods/site/generate.md _methods/site/initialize.md _methods/trailing-dots...md _methods/um_hi.md" in "output/index.html"

Scenario: Documents have an output attribute, which is the converted HTML
Given I have an "index.html" page that contains "Second document's output: {{ site.documents[2].output }}"
Expand Down Expand Up @@ -432,8 +429,7 @@ Feature: Collections
When I run bridgetown build
Then I should get a zero exit status
And the output directory should exist
And I should see "5. of 10: <p>Page without title.</p>" in "output/index.html" unless Windows
And I should see "5. of 9: <p>Page without title.</p>" in "output/index.html" if on Windows
And I should see "5. of 10: <p>Page without title.</p>" in "output/index.html"

Scenario: Sort by relative_path
Given I have an "index.html" page that contains "Collections: {% assign methods = site.methods | sort: 'relative_path' %}{{ methods | map:"title" | join: ", " }}"
Expand All @@ -446,8 +442,7 @@ Feature: Collections
When I run bridgetown build
Then I should get a zero exit status
Then the output directory should exist
And I should see "Collections: this is a test!, Collection#entries, Bridgetown.configuration, Bridgetown.escape, Bridgetown.sanitized_path, Site#generate, Initialize, Ellipsis Path, Site#generate, YAML with Dots" in "output/index.html" unless Windows
And I should see "Collections: this is a test!, Collection#entries, Bridgetown.configuration, Bridgetown.escape, Bridgetown.sanitized_path, Site#generate, Initialize, Ellipsis Path, YAML with Dots" in "output/index.html" if on Windows
And I should see "Collections: this is a test!, Collection#entries, Bridgetown.configuration, Bridgetown.escape, Bridgetown.sanitized_path, Site#generate, Initialize, Ellipsis Path, Site#generate, YAML with Dots" in "output/index.html"

Scenario: Sort all entries by a Front Matter key defined in all entries
Given I have an "index.html" page that contains "Collections: {{ site.tutorials | map: 'title' | join: ', ' }}"
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/features/hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Feature: Hooks
def initialize(site, base)
@site = site
@base = base
@data = {}
@data = HashWithDotAccess::Hash.new
@dir = '/'
@name = 'foo.html'
@content = 'mytinypage'
Expand Down
6 changes: 2 additions & 4 deletions bridgetown-core/features/site_configuration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ Feature: Site configuration
And I should see "Page Layout: 2" in "output/index.html"
And I should see "Post Layout: <p>content for entry1.</p>\n built at" in "output/2013/04/09/entry1.html"
And I should see "Post Layout: <p>content for entry2.</p>\n built at" in "output/2013/04/10/entry2.html"
And I should see date "2013-04-09T23:22:00-04:00" in "output/2013/04/09/entry1.html" unless Windows
And I should see date "2013-04-09T22:22:00-05:00" in "output/2013/04/09/entry1.html" if on Windows
And I should see date "2013-04-10T03:14:00-04:00" in "output/2013/04/10/entry2.html" unless Windows
And I should see date "2013-04-10T02:14:00-05:00" in "output/2013/04/10/entry2.html" if on Windows
And I should see "2013-04-09T23:22:00-04:00" in "output/2013/04/09/entry1.html"
And I should see "2013-04-10T03:14:00-04:00" in "output/2013/04/10/entry2.html"

Scenario: Generate proper dates with explicitly set timezone (different than posts' time)
Given I have a _layouts directory
Expand Down
52 changes: 0 additions & 52 deletions bridgetown-core/features/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,58 +318,6 @@

#

Then(%r!^I should (not )?see "(.*)" in "(.*)" if on Windows$!) do |negative, text, file|
step %(the "#{file}" file should exist)
regexp = Regexp.new(text, Regexp::MULTILINE)
if negative.nil? || negative.empty?
if Bridgetown::Utils::Platforms.really_windows?
expect(file_contents(file)).to match regexp
else
expect(file_contents(file)).not_to match regexp
end
end
end

#

Then(%r!^I should (not )?see "(.*)" in "(.*)" unless Windows$!) do |negative, text, file|
step %(the "#{file}" file should exist)
regexp = Regexp.new(text, Regexp::MULTILINE)
if negative.nil? || negative.empty?
if Bridgetown::Utils::Platforms.really_windows?
expect(file_contents(file)).not_to match regexp
else
expect(file_contents(file)).to match regexp
end
end
end

#

Then(%r!^I should see date "(.*)" in "(.*)" unless Windows$!) do |text, file|
step %(the "#{file}" file should exist)
regexp = Regexp.new(text)
if Bridgetown::Utils::Platforms.really_windows? && !dst_active?
expect(file_contents(file)).not_to match regexp
else
expect(file_contents(file)).to match regexp
end
end

#

Then(%r!^I should see date "(.*)" in "(.*)" if on Windows$!) do |text, file|
step %(the "#{file}" file should exist)
regexp = Regexp.new(text)
if Bridgetown::Utils::Platforms.really_windows? && !dst_active?
expect(file_contents(file)).to match regexp
else
expect(file_contents(file)).not_to match regexp
end
end

#

Then(%r!^I should see exactly "(.*)" in "(.*)"$!) do |text, file|
step %(the "#{file}" file should exist)
expect(file_contents(file).strip).to eq text
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/features/template_engines.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Feature: Template Engines
"""
---
---
<%= jsonify({key: [1, 1+1, 1+1+1]}) %>
<%= raw jsonify({key: [1, 1+1, 1+1+1]}) %>
"""
And I have a configuration file with:
| key | value |
Expand Down
13 changes: 5 additions & 8 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def require_all(path)
require "active_support/core_ext/object/inclusion"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/string/inquiry"
require "active_support/core_ext/string/output_safety"
require "active_support/core_ext/string/starts_ends_with"
require "active_support/current_attributes"
require "active_support/descendants_tracker"
Expand Down Expand Up @@ -67,6 +68,7 @@ class Rb < String; end
module Bridgetown
autoload :Cleaner, "bridgetown-core/cleaner"
autoload :Collection, "bridgetown-core/collection"
autoload :Component, "bridgetown-core/component"
autoload :Configuration, "bridgetown-core/configuration"
autoload :DataAccessible, "bridgetown-core/concerns/data_accessible"
autoload :Deprecator, "bridgetown-core/deprecator"
Expand All @@ -75,9 +77,8 @@ module Bridgetown
# TODO: we have too many errors! This is silly
autoload :Errors, "bridgetown-core/errors"
autoload :Excerpt, "bridgetown-core/excerpt"
# TODO: this is a poorly named, unclear class. Relocate to Utils:
autoload :External, "bridgetown-core/external"
autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
autoload :FrontMatterImporter, "bridgetown-core/concerns/front_matter_importer"
autoload :Hooks, "bridgetown-core/hooks"
autoload :Layout, "bridgetown-core/layout"
autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
Expand All @@ -89,16 +90,12 @@ module Bridgetown
autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
# TODO: remove this when legacy content engine is gone:
autoload :PostReader, "bridgetown-core/readers/post_reader"
# TODO: we can merge this back into Reader class:
# TODO: remove this when legacy content engine is gone:
autoload :PageReader, "bridgetown-core/readers/page_reader"
autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
# TODO: also merge this:
autoload :StaticFileReader, "bridgetown-core/readers/static_file_reader"
autoload :LogAdapter, "bridgetown-core/log_adapter"
autoload :Page, "bridgetown-core/page"
autoload :GeneratedPage, "bridgetown-core/page"
# TODO: figure out how to get rid of this seemingly banal class:
autoload :PathManager, "bridgetown-core/path_manager"
autoload :PluginManager, "bridgetown-core/plugin_manager"
autoload :Publishable, "bridgetown-core/concerns/publishable"
autoload :Publisher, "bridgetown-core/publisher"
Expand Down Expand Up @@ -254,7 +251,7 @@ def sanitized_path(base_directory, questionable_path)
end

# Conditional optimizations
Bridgetown::External.require_if_present("liquid/c")
Bridgetown::Utils::RequireGems.require_if_present("liquid/c")
end
end

Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/lib/bridgetown-core/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def replaced_files
#
# Returns a Set with the directory paths
def keep_dirs
site.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
site.config.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
end

# Private: Creates a regular expression from the config's keep_files array
Expand All @@ -112,7 +112,7 @@ def keep_dirs
#
# Returns the regular expression
def keep_file_regex
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.keep_files).source})!
%r!\A#{Regexp.quote(site.dest)}\/(#{Regexp.union(site.config.keep_files).source})!
end
end
end
25 changes: 14 additions & 11 deletions bridgetown-core/lib/bridgetown-core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def read # rubocop:todo Metrics/PerceivedComplexity, Metrics/CyclomaticComplexit
if site.uses_resource?
next if File.basename(file_path).starts_with?("_")

if label == "data" || Utils.has_yaml_header?(full_path)
if label == "data" || Utils.has_yaml_header?(full_path) ||
Utils.has_rbfm_header?(full_path)
read_resource(full_path)
else
read_static_file(file_path, full_path)
Expand Down Expand Up @@ -256,7 +257,7 @@ def merge_data_resources
sanitized_segment = sanitize_filename.(File.basename(segment, ".*"))
hsh = nested.empty? ? data_contents : data_contents.dig(*nested)
hsh[sanitized_segment] = if index == segments.length - 1
data_resource.data.array || data_resource.data
data_resource.data.rows || data_resource.data
else
{}
end
Expand All @@ -279,6 +280,16 @@ def merge_environment_specific_metadata(data_contents)
data_contents
end

# Read in resource from repo path
# @param full_path [String]
def read_resource(full_path)
id = "repo://#{label}.collection/" + Addressable::URI.escape(
Pathname(full_path).relative_path_from(Pathname(site.source)).to_s
)
resource = Bridgetown::Model::Base.find(id).to_resource.read!
resources << resource if site.config.unpublished || resource.published?
end

private

def container
Expand All @@ -287,15 +298,7 @@ def container

def read_document(full_path)
doc = Document.new(full_path, site: site, collection: self).tap(&:read)
docs << doc if site.unpublished || doc.published?
end

def read_resource(full_path)
id = "file://#{label}.collection/" + Addressable::URI.escape(
Pathname(full_path).relative_path_from(Pathname(site.source)).to_s
)
resource = Bridgetown::Model::Base.find(id).to_resource.read!
resources << resource if site.unpublished || resource.published?
docs << doc if site.config.unpublished || doc.published?
end

def sort_docs!
Expand Down
11 changes: 0 additions & 11 deletions bridgetown-core/lib/bridgetown-core/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ def build_site(config_options)
#
# Returns nothing.
def watch_site(config_options)
# Warn Windows users that they might need to upgrade.
if Utils::Platforms.bash_on_windows?
Bridgetown.logger.warn "",
"Auto-regeneration may not work on some Windows versions."
Bridgetown.logger.warn "",
"Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
Bridgetown.logger.warn "",
"If it does not work, please upgrade Bash on Windows or "\
"run Bridgetown with --no-watch."
end

Bridgetown::Watcher.watch(@site, config_options)
end

Expand Down
20 changes: 1 addition & 19 deletions bridgetown-core/lib/bridgetown-core/commands/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def doctor

def healthy?(site)
[
fsnotify_buggy?(site),
!conflicting_urls(site),
!urls_only_differ_by_case(site),
proper_site_url?(site),
Expand All @@ -59,7 +58,7 @@ def conflicting_urls(site)
conflicting_urls = false
urls = {}
urls = collect_urls(urls, site.pages, site.dest)
urls = collect_urls(urls, site.posts.docs, site.dest)
urls = collect_urls(urls, site.collections.posts.docs, site.dest)
urls.each do |url, paths|
next unless paths.size > 1

Expand All @@ -70,23 +69,6 @@ def conflicting_urls(site)
conflicting_urls
end

def fsnotify_buggy?(_site)
return true unless Utils::Platforms.osx?

if Dir.pwd != `pwd`.strip
Bridgetown.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
We have detected that there might be trouble using fsevent on your
operating system, you can read https://github.com/thibaudgg/rb-fsevent/wiki/no-fsevents-fired-(OSX-bug)
for possible work arounds or you can work around it immediately
with `--force-polling`.
STR

false
end

true
end

def urls_only_differ_by_case(site)
urls_only_differ_by_case = false
urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
Expand Down
8 changes: 4 additions & 4 deletions bridgetown-core/lib/bridgetown-core/commands/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def create_site(new_site_path)
)
template("Gemfile.erb", "Gemfile")
template("package.json.erb", "package.json")
template("webpack.config.js.erb", "webpack.config.js")
template("frontend/javascript/index.js.erb", "frontend/javascript/index.js")

options["use-postcss"] ? configure_postcss : configure_sass
invoke(Webpack, ["setup"], {})
end

def configure_sass
Expand Down Expand Up @@ -140,7 +140,7 @@ def after_install(path, cli_path, options = {})
# rubocop:enable Metrics/PerceivedComplexity

def bundle_install(path)
unless Bridgetown.environment == "test"
unless Bridgetown.environment.test?
require "bundler"
Bridgetown.with_unbundled_env do
inside(path) do
Expand All @@ -156,7 +156,7 @@ def bundle_install(path)
end

def git_init(path)
unless Bridgetown.environment == "test"
unless Bridgetown.environment.test?
inside(path) do
initialize_new_repo
end
Expand All @@ -166,7 +166,7 @@ def git_init(path)
end

def yarn_install(path)
unless Bridgetown.environment == "test"
unless Bridgetown.environment.test?
inside(path) do
run "yarn install", abort_on_failure: true
end
Expand Down
Loading

0 comments on commit 9e80e28

Please sign in to comment.