bridgetown-core 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +0 -1
  3. data/lib/bridgetown-core.rb +11 -22
  4. data/lib/bridgetown-core/cleaner.rb +2 -2
  5. data/lib/bridgetown-core/collection.rb +14 -11
  6. data/lib/bridgetown-core/commands/build.rb +0 -11
  7. data/lib/bridgetown-core/commands/concerns/git_helpers.rb +20 -0
  8. data/lib/bridgetown-core/commands/configure.rb +4 -3
  9. data/lib/bridgetown-core/commands/doctor.rb +1 -19
  10. data/lib/bridgetown-core/commands/new.rb +6 -6
  11. data/lib/bridgetown-core/commands/plugins.rb +14 -13
  12. data/lib/bridgetown-core/commands/serve.rb +0 -14
  13. data/lib/bridgetown-core/commands/webpack.rb +75 -0
  14. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +12 -0
  15. data/lib/bridgetown-core/commands/webpack/setup.rb +4 -0
  16. data/lib/bridgetown-core/commands/webpack/update.rb +3 -0
  17. data/lib/bridgetown-core/commands/webpack/webpack.config.js +18 -0
  18. data/lib/{site_template/webpack.config.js.erb → bridgetown-core/commands/webpack/webpack.defaults.js.erb} +25 -11
  19. data/lib/bridgetown-core/component.rb +183 -0
  20. data/lib/bridgetown-core/concerns/front_matter_importer.rb +52 -0
  21. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  22. data/lib/bridgetown-core/concerns/site/configurable.rb +3 -7
  23. data/lib/bridgetown-core/concerns/site/content.rb +2 -3
  24. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -5
  25. data/lib/bridgetown-core/concerns/site/processable.rb +5 -4
  26. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  27. data/lib/bridgetown-core/concerns/validatable.rb +1 -5
  28. data/lib/bridgetown-core/configuration.rb +22 -14
  29. data/lib/bridgetown-core/configurations/bt-postcss.rb +6 -6
  30. data/lib/bridgetown-core/configurations/netlify.rb +1 -0
  31. data/lib/bridgetown-core/configurations/tailwindcss.rb +6 -6
  32. data/lib/bridgetown-core/converter.rb +9 -0
  33. data/lib/bridgetown-core/converters/erb_templates.rb +51 -35
  34. data/lib/bridgetown-core/converters/liquid_templates.rb +1 -1
  35. data/lib/bridgetown-core/converters/markdown.rb +1 -1
  36. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +2 -38
  37. data/lib/bridgetown-core/converters/ruby_templates.rb +17 -0
  38. data/lib/bridgetown-core/converters/smartypants.rb +3 -1
  39. data/lib/bridgetown-core/core_ext/psych.rb +19 -0
  40. data/lib/bridgetown-core/document.rb +3 -2
  41. data/lib/bridgetown-core/drops/relations_drop.rb +23 -0
  42. data/lib/bridgetown-core/drops/resource_drop.rb +3 -1
  43. data/lib/bridgetown-core/drops/unified_payload_drop.rb +1 -0
  44. data/lib/bridgetown-core/entry_filter.rb +7 -5
  45. data/lib/bridgetown-core/filters.rb +1 -25
  46. data/lib/bridgetown-core/filters/from_liquid.rb +23 -0
  47. data/lib/bridgetown-core/filters/url_filters.rb +12 -0
  48. data/lib/bridgetown-core/frontmatter_defaults.rb +1 -1
  49. data/lib/bridgetown-core/generators/prototype_generator.rb +25 -4
  50. data/lib/bridgetown-core/helpers.rb +48 -9
  51. data/lib/bridgetown-core/layout.rb +52 -20
  52. data/lib/bridgetown-core/model/origin.rb +1 -1
  53. data/lib/bridgetown-core/model/{file_origin.rb → repo_origin.rb} +33 -26
  54. data/lib/bridgetown-core/page.rb +2 -1
  55. data/lib/bridgetown-core/plugin_manager.rb +1 -1
  56. data/lib/bridgetown-core/publisher.rb +2 -2
  57. data/lib/bridgetown-core/reader.rb +13 -11
  58. data/lib/bridgetown-core/readers/data_reader.rb +2 -1
  59. data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
  60. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  61. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  62. data/lib/bridgetown-core/readers/post_reader.rb +5 -4
  63. data/lib/bridgetown-core/regenerator.rb +1 -1
  64. data/lib/bridgetown-core/related_posts.rb +8 -5
  65. data/lib/bridgetown-core/renderer.rb +1 -1
  66. data/lib/bridgetown-core/resource/base.rb +80 -26
  67. data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
  68. data/lib/bridgetown-core/resource/relations.rb +132 -0
  69. data/lib/bridgetown-core/resource/taxonomy_term.rb +10 -1
  70. data/lib/bridgetown-core/resource/taxonomy_type.rb +9 -0
  71. data/lib/bridgetown-core/resource/transformer.rb +18 -14
  72. data/lib/bridgetown-core/ruby_template_view.rb +7 -11
  73. data/lib/bridgetown-core/site.rb +4 -5
  74. data/lib/bridgetown-core/tags/highlight.rb +2 -15
  75. data/lib/bridgetown-core/tags/include.rb +1 -1
  76. data/lib/bridgetown-core/tags/post_url.rb +2 -2
  77. data/lib/bridgetown-core/utils.rb +9 -3
  78. data/lib/bridgetown-core/utils/require_gems.rb +60 -0
  79. data/lib/bridgetown-core/utils/ruby_exec.rb +6 -9
  80. data/lib/bridgetown-core/utils/ruby_front_matter.rb +39 -0
  81. data/lib/bridgetown-core/version.rb +2 -2
  82. data/lib/bridgetown-core/watcher.rb +2 -1
  83. data/lib/bridgetown-core/yaml_parser.rb +22 -0
  84. data/lib/site_template/config/.keep +0 -0
  85. data/lib/site_template/package.json.erb +4 -4
  86. data/lib/site_template/plugins/site_builder.rb +1 -1
  87. data/lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb +1 -1
  88. metadata +21 -23
  89. data/lib/bridgetown-core/external.rb +0 -58
  90. data/lib/bridgetown-core/path_manager.rb +0 -31
  91. data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
  92. data/lib/bridgetown-core/utils/platforms.rb +0 -81
  93. data/lib/bridgetown-core/utils/thread_event.rb +0 -31
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module External
5
- class << self
6
- #
7
- # Require a gem or file if it's present, otherwise silently fail.
8
- #
9
- # names - a string gem name or array of gem names
10
- #
11
- def require_if_present(names)
12
- Array(names).each do |name|
13
- require name
14
- rescue LoadError
15
- Bridgetown.logger.debug "Couldn't load #{name}. Skipping."
16
- yield(name, version_constraint(name)) if block_given?
17
- false
18
- end
19
- end
20
-
21
- #
22
- # The version constraint required to activate a given gem.
23
- #
24
- # Returns a String version constraint in a parseable form for
25
- # RubyGems.
26
- def version_constraint
27
- "> 0"
28
- end
29
-
30
- #
31
- # Require a gem or gems. If it's not present, show a very nice error
32
- # message that explains everything and is much more helpful than the
33
- # normal LoadError.
34
- #
35
- # names - a string gem name or array of gem names
36
- #
37
- def require_with_graceful_fail(names)
38
- Array(names).each do |name|
39
- Bridgetown.logger.debug "Requiring:", name.to_s
40
- require name
41
- rescue LoadError => e
42
- Bridgetown.logger.error "Dependency Error:", <<~MSG
43
- Yikes! It looks like you don't have #{name} or one of its dependencies installed.
44
- In order to use Bridgetown as currently configured, you'll need to install this gem.
45
-
46
- If you've run Bridgetown with `bundle exec`, ensure that you have included the #{name}
47
- gem in your Gemfile as well.
48
-
49
- The full error message from Ruby is: '#{e.message}'
50
-
51
- If you run into trouble, you can find helpful resources at https://www.bridgetownrb.com/docs/community/
52
- MSG
53
- raise Bridgetown::Errors::MissingDependencyException, name
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- # A singleton class that caches frozen instances of path strings returned from its methods.
5
- #
6
- # NOTE:
7
- # This class exists because `File.join` allocates an Array and returns a new String on every
8
- # call using **the same arguments**. Caching the result means reduced memory usage.
9
- # However, the caches are never flushed so that they can be used even when a site is
10
- # regenerating. The results are frozen to deter mutation of the cached string.
11
- #
12
- # Therefore, employ this class only for situations where caching the result is necessary
13
- # for performance reasons.
14
- #
15
- class PathManager
16
- # This class cannot be initialized from outside
17
- private_class_method :new
18
-
19
- # Wraps `File.join` to cache the frozen result.
20
- # Reassigns `nil`, empty strings and empty arrays to a frozen empty string beforehand.
21
- #
22
- # Returns a frozen string.
23
- def self.join(base, item)
24
- base = "" if base.nil? || base.empty?
25
- item = "" if item.nil? || item.empty?
26
- @join ||= {}
27
- @join[base] ||= {}
28
- @join[base][item] ||= File.join(base, item).freeze
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- class StaticFileReader
5
- attr_reader :site, :dir, :unfiltered_content
6
-
7
- def initialize(site, dir)
8
- @site = site
9
- @dir = dir
10
- @unfiltered_content = []
11
- end
12
-
13
- # Create a new StaticFile object for every entry in a given list of basenames.
14
- #
15
- # files - an array of file basenames.
16
- #
17
- # Returns an array of static files.
18
- def read(files)
19
- files.each do |file|
20
- @unfiltered_content << StaticFile.new(@site, @site.source, @dir, file)
21
- end
22
- @unfiltered_content
23
- end
24
- end
25
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Utils
5
- # TODO: deprecate, we should try not to have any platform-specific code
6
- module Platforms
7
- extend self
8
-
9
- # TODO: jruby is NOT supported by Bridgetown. This should probably
10
- # get removed.
11
- { jruby?: "jruby", mri?: "ruby" }.each do |k, v|
12
- define_method k do
13
- ::RUBY_ENGINE == v
14
- end
15
- end
16
-
17
- # --
18
- # Allows you to detect "real" Windows, or what we would consider
19
- # "real" Windows. That is, that we can pass the basic test and the
20
- # /proc/version returns nothing to us.
21
- # --
22
-
23
- def vanilla_windows?
24
- RbConfig::CONFIG["host_os"] =~ %r!mswin|mingw|cygwin!i && \
25
- !proc_version
26
- end
27
-
28
- # --
29
- # XXX: Remove in 4.0
30
- # --
31
-
32
- alias_method :really_windows?, \
33
- :vanilla_windows?
34
-
35
- #
36
-
37
- def bash_on_windows?
38
- RbConfig::CONFIG["host_os"] =~ %r!linux! && \
39
- proc_version =~ %r!microsoft!i
40
- end
41
-
42
- #
43
-
44
- def windows?
45
- vanilla_windows? || bash_on_windows?
46
- end
47
-
48
- #
49
-
50
- def linux?
51
- RbConfig::CONFIG["host_os"] =~ %r!linux! && \
52
- proc_version !~ %r!microsoft!i
53
- end
54
-
55
- # Provides windows?, linux?, osx?, unix? so that we can detect
56
- # platforms. This is mostly useful for `bridgetown doctor` and for testing
57
- # where we kick off certain tests based on the platform.
58
-
59
- { osx?: %r!darwin|mac os!, unix?: %r!solaris|bsd! }.each do |k, v|
60
- define_method k do
61
- !!(
62
- RbConfig::CONFIG["host_os"] =~ v
63
- )
64
- end
65
- end
66
-
67
- #
68
-
69
- private
70
-
71
- def proc_version
72
- @proc_version ||=
73
- begin
74
- File.read("/proc/version")
75
- rescue Errno::ENOENT, Errno::EACCES
76
- nil
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Utils
5
- # Based on the pattern and code from
6
- # https://emptysqua.re/blog/an-event-synchronization-primitive-for-ruby/
7
- class ThreadEvent
8
- attr_reader :flag
9
-
10
- def initialize
11
- @lock = Mutex.new
12
- @cond = ConditionVariable.new
13
- @flag = false
14
- end
15
-
16
- def set
17
- @lock.synchronize do
18
- yield if block_given?
19
- @flag = true
20
- @cond.broadcast
21
- end
22
- end
23
-
24
- def wait
25
- @lock.synchronize do
26
- @cond.wait(@lock) unless @flag
27
- end
28
- end
29
- end
30
- end
31
- end