bridgetown-core 0.15.0.beta1 → 0.16.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/bridgetown-core.gemspec +2 -0
  4. data/lib/bridgetown-core.rb +6 -1
  5. data/lib/bridgetown-core/commands/concerns/actions.rb +54 -21
  6. data/lib/bridgetown-core/commands/console.rb +12 -2
  7. data/lib/bridgetown-core/commands/serve.rb +5 -0
  8. data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
  9. data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
  10. data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
  11. data/lib/bridgetown-core/concerns/publishable.rb +10 -0
  12. data/lib/bridgetown-core/concerns/site/configurable.rb +62 -31
  13. data/lib/bridgetown-core/concerns/site/content.rb +88 -29
  14. data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
  15. data/lib/bridgetown-core/concerns/site/processable.rb +12 -10
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +23 -4
  17. data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
  18. data/lib/bridgetown-core/concerns/validatable.rb +59 -0
  19. data/lib/bridgetown-core/configuration.rb +1 -0
  20. data/lib/bridgetown-core/converter.rb +34 -0
  21. data/lib/bridgetown-core/converters/erb_templates.rb +61 -0
  22. data/lib/bridgetown-core/converters/markdown.rb +6 -23
  23. data/lib/bridgetown-core/converters/smartypants.rb +0 -10
  24. data/lib/bridgetown-core/document.rb +8 -52
  25. data/lib/bridgetown-core/drops/document_drop.rb +9 -1
  26. data/lib/bridgetown-core/drops/page_drop.rb +1 -1
  27. data/lib/bridgetown-core/errors.rb +2 -0
  28. data/lib/bridgetown-core/excerpt.rb +5 -7
  29. data/lib/bridgetown-core/filters.rb +2 -0
  30. data/lib/bridgetown-core/layout.rb +24 -1
  31. data/lib/bridgetown-core/liquid_renderer/file.rb +1 -4
  32. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
  33. data/lib/bridgetown-core/page.rb +36 -42
  34. data/lib/bridgetown-core/plugin_manager.rb +27 -13
  35. data/lib/bridgetown-core/regenerator.rb +1 -1
  36. data/lib/bridgetown-core/renderer.rb +41 -15
  37. data/lib/bridgetown-core/ruby_template_view.rb +84 -0
  38. data/lib/bridgetown-core/tags/class_map.rb +90 -0
  39. data/lib/bridgetown-core/tags/include.rb +2 -0
  40. data/lib/bridgetown-core/tags/render_content.rb +14 -2
  41. data/lib/bridgetown-core/tags/webpack_path.rb +48 -16
  42. data/lib/bridgetown-core/utils.rb +44 -0
  43. data/lib/bridgetown-core/version.rb +2 -2
  44. data/lib/site_template/bridgetown.config.yml +5 -3
  45. data/lib/site_template/package.json +1 -0
  46. data/lib/site_template/src/_components/{footer.html → footer.liquid} +0 -0
  47. data/lib/site_template/src/_components/{head.html → head.liquid} +0 -0
  48. data/lib/site_template/src/_components/{navbar.html → navbar.liquid} +0 -0
  49. data/lib/site_template/src/_layouts/default.html +1 -1
  50. data/lib/site_template/webpack.config.js +3 -3
  51. metadata +41 -6
  52. data/lib/bridgetown-core/concerns/convertible.rb +0 -238
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba553587c222b3cedc1844d3bf40845a83dd24d70e3c85d49965ad010687e1b5
4
- data.tar.gz: 223fea6ecf255ebaab06e34d3f8fa8e47ab64d0dd63d2dffc5cd25361a232ded
3
+ metadata.gz: 25a57f1cf4e0a06e347edf5c97c78a168bc56f5efab6fdcf7f55a78ac491a3de
4
+ data.tar.gz: 96f00f4e411b8f46467d3f8ff6ecb153c07a34f5496f4109361afdfe8d7493c0
5
5
  SHA512:
6
- metadata.gz: dbb889837e2ef982295b2880d76bf6f928ba808b048792250c201bf101eff0151406bad78ed1ea2229d1f1bd572c7b031889386c7dc765506f5f631c30825aff
7
- data.tar.gz: c6c582d64cab40f9ad203752cc8168b91e446a6535716ea7d318359990ab74f256c57b2a910bed1fbfce316a590e389901a1335770d9171c6ae3852509625ef5
6
+ metadata.gz: 378534362fb45c10c4aef9600771e10d13d07f827309ee2dd2395ff5c60a9b36c1e1b309e48274de3ef09ac9d16178ad563d49da437535961ba27844c86020d0
7
+ data.tar.gz: dda52cf9adc2768b57dc93677babdd63b5d1e500a8fbfe7c69f0dcb719701f3b986ae740d3fca703932f346b172b23e0c8561549a7f1dddad7b3b97b3605e535
data/Rakefile CHANGED
@@ -12,3 +12,17 @@ Rake::TestTask.new(:test) do |test|
12
12
  test.pattern = "test/**/test_*.rb"
13
13
  test.verbose = true
14
14
  end
15
+
16
+ require 'yard'
17
+ YARD::Rake::YardocTask.new(:yard) do |t|
18
+ t.files = ['lib/**/*.rb']
19
+ t.options = ['--no-output']
20
+ t.stats_options = ['--list-undoc']
21
+ end
22
+
23
+ namespace :yard do
24
+ task :serve do
25
+ port = ENV['YARD_PORT'] || "8808"
26
+ sh("yard server --reload -p #{port}")
27
+ end
28
+ end
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
 
34
34
  s.add_runtime_dependency("activesupport", "~> 6.0")
35
35
  s.add_runtime_dependency("addressable", "~> 2.4")
36
+ s.add_runtime_dependency("awesome_print", "~> 1.8")
36
37
  s.add_runtime_dependency("colorator", "~> 1.0")
37
38
  s.add_runtime_dependency("faraday", "~> 1.0")
38
39
  s.add_runtime_dependency("faraday_middleware", "~> 1.0")
@@ -48,4 +49,5 @@ Gem::Specification.new do |s|
48
49
  s.add_runtime_dependency("safe_yaml", "~> 1.0")
49
50
  s.add_runtime_dependency("terminal-table", "~> 1.8")
50
51
  s.add_runtime_dependency("thor", "~> 1.0")
52
+ s.add_runtime_dependency("tilt", "~> 2.0")
51
53
  end
@@ -54,7 +54,7 @@ module Bridgetown
54
54
  autoload :Cleaner, "bridgetown-core/cleaner"
55
55
  autoload :Collection, "bridgetown-core/collection"
56
56
  autoload :Configuration, "bridgetown-core/configuration"
57
- autoload :Convertible, "bridgetown-core/concerns/convertible"
57
+ autoload :DataAccessible, "bridgetown-core/concerns/data_accessible"
58
58
  autoload :Deprecator, "bridgetown-core/deprecator"
59
59
  autoload :Document, "bridgetown-core/document"
60
60
  autoload :EntryFilter, "bridgetown-core/entry_filter"
@@ -64,6 +64,7 @@ module Bridgetown
64
64
  autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
65
65
  autoload :Hooks, "bridgetown-core/hooks"
66
66
  autoload :Layout, "bridgetown-core/layout"
67
+ autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
67
68
  autoload :Cache, "bridgetown-core/cache"
68
69
  autoload :CollectionReader, "bridgetown-core/readers/collection_reader"
69
70
  autoload :DataReader, "bridgetown-core/readers/data_reader"
@@ -77,17 +78,21 @@ module Bridgetown
77
78
  autoload :PageWithoutAFile, "bridgetown-core/page_without_a_file"
78
79
  autoload :PathManager, "bridgetown-core/path_manager"
79
80
  autoload :PluginManager, "bridgetown-core/plugin_manager"
81
+ autoload :Publishable, "bridgetown-core/concerns/publishable"
80
82
  autoload :Publisher, "bridgetown-core/publisher"
81
83
  autoload :Reader, "bridgetown-core/reader"
82
84
  autoload :Regenerator, "bridgetown-core/regenerator"
83
85
  autoload :RelatedPosts, "bridgetown-core/related_posts"
84
86
  autoload :Renderer, "bridgetown-core/renderer"
87
+ autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
85
88
  autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
89
+ autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
86
90
  autoload :LogWriter, "bridgetown-core/log_writer"
87
91
  autoload :Site, "bridgetown-core/site"
88
92
  autoload :StaticFile, "bridgetown-core/static_file"
89
93
  autoload :URL, "bridgetown-core/url"
90
94
  autoload :Utils, "bridgetown-core/utils"
95
+ autoload :Validatable, "bridgetown-core/concerns/validatable"
91
96
  autoload :VERSION, "bridgetown-core/version"
92
97
  autoload :Watcher, "bridgetown-core/watcher"
93
98
 
@@ -8,9 +8,24 @@ require "active_support/core_ext/string/indent"
8
8
  module Bridgetown
9
9
  module Commands
10
10
  module Actions
11
+ GITHUB_REGEX = %r!https://github\.com!.freeze
12
+ GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!.freeze
13
+ GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!.freeze
14
+
11
15
  def create_builder(filename, data = nil)
12
16
  say_status :create_builder, filename
13
17
  data ||= yield if block_given?
18
+
19
+ site_builder = File.join("plugins", "site_builder.rb")
20
+ unless File.exist?(site_builder)
21
+ create_file("plugins/site_builder.rb", verbose: true) do
22
+ <<~RUBY
23
+ class SiteBuilder < Bridgetown::Builder
24
+ end
25
+ RUBY
26
+ end
27
+ end
28
+
14
29
  create_file("plugins/builders/#{filename}", data, verbose: false)
15
30
  end
16
31
 
@@ -66,30 +81,48 @@ module Bridgetown
66
81
 
67
82
  private
68
83
 
69
- def transform_automation_url(arg)
70
- remote_file = if arg.end_with?(".rb")
71
- arg.split("/").yield_self do |segments|
72
- arg.sub!(%r!/#{segments.last}$!, "")
73
- segments.last
74
- end
75
- else
76
- "bridgetown.automation.rb"
77
- end
78
-
79
- if arg.start_with?("https://gist.github.com")
80
- return arg.sub(
81
- "https://gist.github.com", "https://gist.githubusercontent.com"
82
- ) + "/raw/#{remote_file}"
83
- elsif arg.start_with?("https://github.com")
84
- return arg.sub(
85
- "https://github.com", "https://raw.githubusercontent.com"
86
- ) + "/master/#{remote_file}"
84
+ def determine_remote_filename(arg)
85
+ if arg.end_with?(".rb")
86
+ arg.split("/").yield_self do |segments|
87
+ arg.sub!(%r!/#{segments.last}$!, "")
88
+ segments.last
89
+ end
90
+ else
91
+ "bridgetown.automation.rb"
87
92
  end
93
+ end
88
94
 
89
- # TODO: option to download and confirm remote automation?
90
-
91
- arg
95
+ # TODO: option to download and confirm remote automation?
96
+ # rubocop:disable Metrics/MethodLength
97
+ def transform_automation_url(arg)
98
+ return arg unless arg.start_with?("http")
99
+
100
+ remote_file = determine_remote_filename(arg)
101
+ github_match = GITHUB_REGEX.match(arg)
102
+
103
+ arg = if arg.start_with?("https://gist.github.com")
104
+ arg.sub(
105
+ "https://gist.github.com", "https://gist.githubusercontent.com"
106
+ ) + "/raw"
107
+ elsif github_match
108
+ new_url = arg.sub(GITHUB_REGEX, "https://raw.githubusercontent.com")
109
+ github_tree_match = GITHUB_TREE_REGEX.match(arg)
110
+ github_blob_match = GITHUB_BLOB_REGEX.match(arg)
111
+
112
+ if github_tree_match
113
+ new_url.sub("/tree/", "/")
114
+ elsif github_blob_match
115
+ new_url.sub("/blob/", "/")
116
+ else
117
+ "#{new_url}/master"
118
+ end
119
+ else
120
+ arg
121
+ end
122
+
123
+ "#{arg}/#{remote_file}"
92
124
  end
125
+ # rubocop:enable Metrics/MethodLength
93
126
  end
94
127
  end
95
128
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "irb"
4
-
5
3
  module Bridgetown
6
4
  module Commands
7
5
  class Console < Thor::Group
@@ -21,11 +19,17 @@ module Bridgetown
21
19
  type: :array,
22
20
  banner: "FILE1 FILE2",
23
21
  desc: "Custom configuration file(s)"
22
+ class_option :"bypass-ap",
23
+ type: :boolean,
24
+ desc: "Don't load AwesomePrint when IRB opens"
24
25
  class_option :blank,
25
26
  type: :boolean,
26
27
  desc: "Skip reading content and running generators before opening console"
27
28
 
28
29
  def console
30
+ require "irb"
31
+ require "awesome_print" unless options[:"bypass-ap"]
32
+
29
33
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
30
34
  " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
31
35
  " console…"
@@ -56,6 +60,12 @@ module Bridgetown
56
60
 
57
61
  begin
58
62
  catch(:IRB_EXIT) do
63
+ unless options[:"bypass-ap"]
64
+ AwesomePrint.defaults = {
65
+ indent: 2,
66
+ }
67
+ AwesomePrint.irb!
68
+ end
59
69
  irb.eval_input
60
70
  end
61
71
  end
@@ -29,6 +29,11 @@ module Bridgetown
29
29
  class_option :skip_initial_build,
30
30
  type: :boolean,
31
31
  desc: "Skips the initial site build which occurs before the server is started."
32
+ class_option :watch,
33
+ type: :boolean,
34
+ aliases: "-w",
35
+ default: true,
36
+ desc: "Watch for changes and rebuild"
32
37
 
33
38
  def self.banner
34
39
  "bridgetown serve [options]"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module DataAccessible
5
+ # Returns the contents as a String.
6
+ def to_s
7
+ output || content || ""
8
+ end
9
+
10
+ # Accessor for data properties by Liquid.
11
+ #
12
+ # property - The String name of the property to retrieve.
13
+ #
14
+ # Returns the String value or nil if the property isn't included.
15
+ def [](property)
16
+ data[property]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module LayoutPlaceable
5
+ # Determine whether the file should be placed into layouts.
6
+ #
7
+ # Returns false if the document is an asset file or if the front matter
8
+ # specifies `layout: none`
9
+ def place_in_layout?
10
+ !(yaml_file? || no_layout?)
11
+ end
12
+
13
+ def no_layout?
14
+ data["layout"] == "none"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module LiquidRenderable
5
+ # Determine whether the file should be rendered with Liquid.
6
+ #
7
+ # Returns false if the document is a yaml file or if the document doesn't
8
+ # contain any Liquid Tags or Variables, true otherwise.
9
+ def render_with_liquid?
10
+ return false if data["render_with_liquid"] == false
11
+
12
+ !(yaml_file? || !Utils.has_liquid_construct?(content))
13
+ end
14
+
15
+ # Override in individual classes
16
+ def yaml_file?
17
+ false
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Publishable
5
+ # Whether the file is published or not, as indicated in YAML front-matter
6
+ def published?
7
+ !(data.key?("published") && data["published"] == false)
8
+ end
9
+ end
10
+ end
@@ -2,12 +2,17 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Site::Configurable
5
- # Public: Set the site's configuration. This handles side-effects caused by
5
+ # Set the site's configuration. This handles side-effects caused by
6
6
  # changing values in the configuration.
7
7
  #
8
- # config - a Bridgetown::Configuration, containing the new configuration.
8
+ # @param config [Bridgetown::Configuration]
9
+ # An instance of {Bridgetown::Configuration},
10
+ # containing the new configuration.
9
11
  #
10
- # Returns the new configuration.
12
+ # @return [Bridgetown::Configuration]
13
+ # A new instance of {Bridgetown::Configuration}
14
+ #
15
+ # @see Bridgetown::Configuration
11
16
  def config=(config)
12
17
  @config = config.clone
13
18
 
@@ -32,81 +37,107 @@ module Bridgetown
32
37
  @config
33
38
  end
34
39
 
35
- # Returns the FrontmatterDefaults or creates a new FrontmatterDefaults
36
- # if it doesn't already exist.
40
+ # Returns the current instance of {FrontmatterDefaults} or
41
+ # creates a new instance {FrontmatterDefaults} if it doesn't already exist.
37
42
  #
38
- # Returns The FrontmatterDefaults
43
+ # @return [FrontmatterDefaults]
44
+ # Returns an instance of {FrontmatterDefaults}
39
45
  def frontmatter_defaults
40
46
  @frontmatter_defaults ||= FrontmatterDefaults.new(self)
41
47
  end
42
48
 
43
- # Whether to perform a full rebuild without incremental regeneration
49
+ # Whether to perform a full rebuild without incremental regeneration.
50
+ # If either +override+["incremental"] or +config+["incremental"] are true,
51
+ # fully rebuild the site. If not, incrementally build the site.
44
52
  #
45
- # Returns a Boolean: true for a full rebuild, false for normal build
53
+ # @param [Hash] override
54
+ # An override hash to override the current config value
55
+ # @option override [Boolean] "incremental" Whether to incrementally build
56
+ # @return [Boolean] true for full rebuild, false for normal build
46
57
  def incremental?(override = {})
47
58
  override["incremental"] || config["incremental"]
48
59
  end
49
60
 
50
- # Returns the publisher or creates a new publisher if it doesn't
51
- # already exist.
61
+ # Returns the current instance of {Publisher} or creates a new instance of
62
+ # {Publisher} if one doesn't exist.
52
63
  #
53
- # Returns The Publisher
64
+ # @return [Publisher] Returns an instance of {Publisher}
54
65
  def publisher
55
66
  @publisher ||= Publisher.new(self)
56
67
  end
57
68
 
58
- # Public: Prefix a given path with the root directory.
69
+ # Prefix a path or paths with the {#root_dir} directory.
59
70
  #
60
- # paths - (optional) path elements to a file or directory within the
61
- # root directory
71
+ # @see Bridgetown.sanitized_path
72
+ # @param paths [Array<String>]
73
+ # An array of paths to prefix with the root_dir directory using the
74
+ # {Bridgetown.sanitized_path} method.
62
75
  #
63
- # Returns a path which is prefixed with the root_dir directory.
76
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
64
77
  def in_root_dir(*paths)
65
78
  paths.reduce(root_dir) do |base, path|
66
79
  Bridgetown.sanitized_path(base, path)
67
80
  end
68
81
  end
69
82
 
70
- # Public: Prefix a given path with the source directory.
71
- #
72
- # paths - (optional) path elements to a file or directory within the
73
- # source directory
83
+ # Prefix a path or paths with the {#source} directory.
74
84
  #
75
- # Returns a path which is prefixed with the source directory.
85
+ # @see Bridgetown.sanitized_path
86
+ # @param paths [Array<String>]
87
+ # An array of paths to prefix with the source directory using the
88
+ # {Bridgetown.sanitized_path} method.
89
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
76
90
  def in_source_dir(*paths)
77
91
  paths.reduce(source) do |base, path|
78
92
  Bridgetown.sanitized_path(base, path)
79
93
  end
80
94
  end
81
95
 
82
- # Public: Prefix a given path with the destination directory.
96
+ # Prefix a path or paths with the {#dest} directory.
83
97
  #
84
- # paths - (optional) path elements to a file or directory within the
85
- # destination directory
98
+ # @see Bridgetown.sanitized_path
99
+ # @param paths [Array<String>]
100
+ # An array of paths to prefix with the destination directory using the
101
+ # {Bridgetown.sanitized_path} method.
86
102
  #
87
- # Returns a path which is prefixed with the destination directory.
103
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
88
104
  def in_dest_dir(*paths)
89
105
  paths.reduce(dest) do |base, path|
90
106
  Bridgetown.sanitized_path(base, path)
91
107
  end
92
108
  end
93
109
 
94
- # Public: Prefix a given path with the cache directory.
110
+ # Prefix a path or paths with the {#cache_dir} directory.
95
111
  #
96
- # paths - (optional) path elements to a file or directory within the
97
- # cache directory
112
+ # @see Bridgetown.sanitized_path
113
+ # @param paths [Array<String>]
114
+ # An array of paths to prefix with the {#cache_dir} directory using the
115
+ # {Bridgetown.sanitized_path} method.
98
116
  #
99
- # Returns a path which is prefixed with the cache directory.
117
+ # @return [Array<String>] Return an array of updated paths if multiple paths given.
100
118
  def in_cache_dir(*paths)
101
119
  paths.reduce(cache_dir) do |base, path|
102
120
  Bridgetown.sanitized_path(base, path)
103
121
  end
104
122
  end
105
123
 
106
- # Public: The full path to the directory that houses all the collections registered
107
- # with the current site.
124
+ # The full path to the directory that houses all the registered collections
125
+ # for the current site.
126
+ #
127
+ # If +@collections_path+ is specified use its value.
128
+ #
129
+ # If +@collections+ is not specified and +config+["collections_dir"] is
130
+ # specified, prepend it with {#source} and assign it to
131
+ # {#collections_path}.
132
+ #
133
+ # If +@collections+ is not specified and +config+["collections_dir"] is not
134
+ # specified, assign {#source} to +@collections_path+
108
135
  #
109
- # Returns the source directory or the absolute path to the custom collections_dir
136
+ # @return [String] Returns the full path to the collections directory
137
+ # @see #config
138
+ # @see #source
139
+ # @see #collections_path
140
+ # @see #in_source_dir
110
141
  def collections_path
111
142
  dir_str = config["collections_dir"]
112
143
  @collections_path ||= dir_str.empty? ? source : in_source_dir(dir_str)