bridgetown-core 0.21.0.beta1 → 0.21.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bridgetown-core.rb +2 -8
  3. data/lib/bridgetown-core/commands/build.rb +0 -11
  4. data/lib/bridgetown-core/commands/doctor.rb +1 -19
  5. data/lib/bridgetown-core/commands/serve.rb +0 -14
  6. data/lib/bridgetown-core/configuration.rb +1 -1
  7. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +2 -38
  8. data/lib/bridgetown-core/converters/smartypants.rb +3 -1
  9. data/lib/bridgetown-core/document.rb +1 -0
  10. data/lib/bridgetown-core/entry_filter.rb +2 -2
  11. data/lib/bridgetown-core/filters.rb +1 -25
  12. data/lib/bridgetown-core/filters/url_filters.rb +12 -0
  13. data/lib/bridgetown-core/page.rb +2 -1
  14. data/lib/bridgetown-core/plugin_manager.rb +1 -1
  15. data/lib/bridgetown-core/reader.rb +10 -8
  16. data/lib/bridgetown-core/readers/data_reader.rb +1 -0
  17. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  18. data/lib/bridgetown-core/readers/post_reader.rb +5 -4
  19. data/lib/bridgetown-core/related_posts.rb +4 -4
  20. data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
  21. data/lib/bridgetown-core/tags/include.rb +1 -1
  22. data/lib/bridgetown-core/tags/post_url.rb +2 -2
  23. data/lib/bridgetown-core/utils.rb +1 -2
  24. data/lib/bridgetown-core/utils/require_gems.rb +60 -0
  25. data/lib/bridgetown-core/version.rb +1 -1
  26. metadata +3 -7
  27. data/lib/bridgetown-core/external.rb +0 -58
  28. data/lib/bridgetown-core/path_manager.rb +0 -31
  29. data/lib/bridgetown-core/readers/static_file_reader.rb +0 -25
  30. data/lib/bridgetown-core/utils/platforms.rb +0 -81
  31. data/lib/bridgetown-core/utils/thread_event.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02c8827143ec0abe2adfa081ef1fe7723d8d000c4ecec5c6da1ddaa2ef9a8cdf
4
- data.tar.gz: 2c81ef34075b80ce956f43b57b01b400852d4a30e3eca8587785febc5c82a850
3
+ metadata.gz: b5271d5bbaf78f54da137c78c0885ca8ca7b66787ea432c362bd1c51416a39c2
4
+ data.tar.gz: 440500addaa640424b810080179b9e20b22bf9f2936605c77635563c0f102cd1
5
5
  SHA512:
6
- metadata.gz: f86157dcd3f2fb1139e490fcc1341e2508f4811bda806171e2374e4753cf14c6c121abbb2ceeb6536a925bfd1d1ecba44c6d35fb6ebd6c0bcad3b4ace8d73912
7
- data.tar.gz: 9262363b23785be1ad111a611d7660201dd3e948e331fdcf5395afd8fde91f1cb075ba13d1729fcd537cd15e3d209c8016145af04c13f054f87bb37d46406617
6
+ metadata.gz: 375d68544812f8238a226aa6a9986baa74bf08a19d674f1290729ffe556c9a9af29887ef215acd219e6a7e2c0f29fa90c4832afe72c8c37425e3746fa6367531
7
+ data.tar.gz: 1bc5fcb4c65abf6c394332d891883547106ddb2d233519766578bc33fe1778bd1e97ee830c9dc33f556a7e2486d36f17e6534482b3b51f1af0ca8d463ba6c105
@@ -90,8 +90,6 @@ module Bridgetown
90
90
  # TODO: we have too many errors! This is silly
91
91
  autoload :Errors, "bridgetown-core/errors"
92
92
  autoload :Excerpt, "bridgetown-core/excerpt"
93
- # TODO: this is a poorly named, unclear class. Relocate to Utils:
94
- autoload :External, "bridgetown-core/external"
95
93
  autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
96
94
  autoload :FrontMatterImporter, "bridgetown-core/concerns/front_matter_importer"
97
95
  autoload :Hooks, "bridgetown-core/hooks"
@@ -105,16 +103,12 @@ module Bridgetown
105
103
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
106
104
  # TODO: remove this when legacy content engine is gone:
107
105
  autoload :PostReader, "bridgetown-core/readers/post_reader"
108
- # TODO: we can merge this back into Reader class:
106
+ # TODO: remove this when legacy content engine is gone:
109
107
  autoload :PageReader, "bridgetown-core/readers/page_reader"
110
108
  autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
111
- # TODO: also merge this:
112
- autoload :StaticFileReader, "bridgetown-core/readers/static_file_reader"
113
109
  autoload :LogAdapter, "bridgetown-core/log_adapter"
114
110
  autoload :Page, "bridgetown-core/page"
115
111
  autoload :GeneratedPage, "bridgetown-core/page"
116
- # TODO: figure out how to get rid of this seemingly banal class:
117
- autoload :PathManager, "bridgetown-core/path_manager"
118
112
  autoload :PluginManager, "bridgetown-core/plugin_manager"
119
113
  autoload :Publishable, "bridgetown-core/concerns/publishable"
120
114
  autoload :Publisher, "bridgetown-core/publisher"
@@ -268,7 +262,7 @@ module Bridgetown
268
262
  end
269
263
 
270
264
  # Conditional optimizations
271
- Bridgetown::External.require_if_present("liquid/c")
265
+ Bridgetown::Utils::RequireGems.require_if_present("liquid/c")
272
266
  end
273
267
  end
274
268
 
@@ -79,17 +79,6 @@ module Bridgetown
79
79
  #
80
80
  # Returns nothing.
81
81
  def watch_site(config_options)
82
- # Warn Windows users that they might need to upgrade.
83
- if Utils::Platforms.bash_on_windows?
84
- Bridgetown.logger.warn "",
85
- "Auto-regeneration may not work on some Windows versions."
86
- Bridgetown.logger.warn "",
87
- "Please see: https://github.com/Microsoft/BashOnWindows/issues/216"
88
- Bridgetown.logger.warn "",
89
- "If it does not work, please upgrade Bash on Windows or "\
90
- "run Bridgetown with --no-watch."
91
- end
92
-
93
82
  Bridgetown::Watcher.watch(@site, config_options)
94
83
  end
95
84
 
@@ -33,7 +33,6 @@ module Bridgetown
33
33
 
34
34
  def healthy?(site)
35
35
  [
36
- fsnotify_buggy?(site),
37
36
  !conflicting_urls(site),
38
37
  !urls_only_differ_by_case(site),
39
38
  proper_site_url?(site),
@@ -59,7 +58,7 @@ module Bridgetown
59
58
  conflicting_urls = false
60
59
  urls = {}
61
60
  urls = collect_urls(urls, site.pages, site.dest)
62
- urls = collect_urls(urls, site.posts.docs, site.dest)
61
+ urls = collect_urls(urls, site.collections.posts.docs, site.dest)
63
62
  urls.each do |url, paths|
64
63
  next unless paths.size > 1
65
64
 
@@ -70,23 +69,6 @@ module Bridgetown
70
69
  conflicting_urls
71
70
  end
72
71
 
73
- def fsnotify_buggy?(_site)
74
- return true unless Utils::Platforms.osx?
75
-
76
- if Dir.pwd != `pwd`.strip
77
- Bridgetown.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
78
- We have detected that there might be trouble using fsevent on your
79
- operating system, you can read https://github.com/thibaudgg/rb-fsevent/wiki/no-fsevents-fired-(OSX-bug)
80
- for possible work arounds or you can work around it immediately
81
- with `--force-polling`.
82
- STR
83
-
84
- false
85
- end
86
-
87
- true
88
- end
89
-
90
72
  def urls_only_differ_by_case(site)
91
73
  urls_only_differ_by_case = false
92
74
  urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
@@ -13,10 +13,6 @@ module Bridgetown
13
13
 
14
14
  class_option :host, aliases: "-H", desc: "Host to bind to"
15
15
  class_option :port, aliases: "-P", desc: "Port to listen on"
16
- class_option :open_url,
17
- aliases: "-o",
18
- type: :boolean,
19
- desc: "Launch your site in a browser"
20
16
  class_option :detach,
21
17
  aliases: "-B",
22
18
  type: :boolean,
@@ -169,16 +165,6 @@ module Bridgetown
169
165
  )
170
166
  end
171
167
 
172
- def launch_browser(server, opts)
173
- address = server_address(server, opts)
174
- return system "start", address if Utils::Platforms.windows?
175
- return system "xdg-open", address if Utils::Platforms.linux?
176
- return system "open", address if Utils::Platforms.osx?
177
-
178
- Bridgetown.logger.error "Refusing to launch browser; " \
179
- "Platform launcher unknown."
180
- end
181
-
182
168
  # Keep in our area with a thread or detach the server as requested
183
169
  # by the user. This method determines what we do based on what you
184
170
  # ask us to do.
@@ -144,7 +144,7 @@ module Bridgetown
144
144
  def safe_load_file(filename)
145
145
  case File.extname(filename)
146
146
  when %r!\.toml!i
147
- Bridgetown::External.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
147
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail("tomlrb") unless defined?(Tomlrb)
148
148
  Tomlrb.load_file(filename)
149
149
  when %r!\.ya?ml!i
150
150
  SafeYAML.load_file(filename) || {}
@@ -72,21 +72,11 @@ module Bridgetown
72
72
  attr_reader :extractions
73
73
 
74
74
  def initialize(config)
75
- @main_fallback_highlighter = config["highlighter"] || "rouge"
76
75
  @config = config["kramdown"] || {}
77
- @highlighter = nil
78
- setup
79
- load_dependencies
80
- end
81
-
82
- # Setup and normalize the configuration:
83
- # * Create Kramdown if it doesn't exist.
84
- # * Set syntax_highlighter
85
- # * Make sure `syntax_highlighter_opts` exists.
86
- def setup
87
- @config["syntax_highlighter"] ||= highlighter
76
+ @config["syntax_highlighter"] ||= config["highlighter"] || "rouge"
88
77
  @config["syntax_highlighter_opts"] ||= {}
89
78
  @config["syntax_highlighter_opts"]["guess_lang"] = @config["guess_lang"]
79
+ require "kramdown-parser-gfm" if @config["input"] == "GFM"
90
80
  end
91
81
 
92
82
  def convert(content)
@@ -100,32 +90,6 @@ module Bridgetown
100
90
  @extractions = document.root.options[:extractions] # could be nil
101
91
  html_output
102
92
  end
103
-
104
- private
105
-
106
- def load_dependencies
107
- require "kramdown-parser-gfm" if @config["input"] == "GFM"
108
-
109
- # `mathjax` emgine is bundled within kramdown-2.x and will be handled by
110
- # kramdown itself.
111
- if (math_engine = @config["math_engine"]) && math_engine != "mathjax"
112
- Bridgetown::External.require_with_graceful_fail("kramdown-math-#{math_engine}")
113
- end
114
- end
115
-
116
- # config[kramdown][syntax_higlighter] >
117
- # config[highlighter]
118
- def highlighter
119
- return @highlighter if @highlighter
120
-
121
- if @config["syntax_highlighter"]
122
- return @highlighter = @config[
123
- "syntax_highlighter"
124
- ]
125
- end
126
-
127
- @highlighter = @main_fallback_highlighter
128
- end
129
93
  end
130
94
  end
131
95
  end
@@ -25,7 +25,9 @@ module Bridgetown
25
25
  priority :low
26
26
 
27
27
  def initialize(config)
28
- Bridgetown::External.require_with_graceful_fail "kramdown" unless defined?(Kramdown)
28
+ unless defined?(Kramdown)
29
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail "kramdown"
30
+ end
29
31
  @config = config["kramdown"].dup || {}
30
32
  @config[:input] = :SmartyPants
31
33
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ # TODO: to be retired once the Resource engine is made official
4
5
  class Document
5
6
  extend Forwardable
6
7
  include DataAccessible
@@ -75,12 +75,12 @@ module Bridgetown
75
75
  # Check if an entry matches a specific pattern.
76
76
  # Returns true if path matches against any glob pattern, else false.
77
77
  def glob_include?(enumerator, entry)
78
- entry_with_source = PathManager.join(site.source, entry)
78
+ entry_with_source = File.join(site.source, entry)
79
79
 
80
80
  enumerator.any? do |pattern|
81
81
  case pattern
82
82
  when String
83
- pattern_with_source = PathManager.join(site.source, pattern)
83
+ pattern_with_source = File.join(site.source, pattern)
84
84
 
85
85
  File.fnmatch?(pattern_with_source, entry_with_source) ||
86
86
  entry_with_source.start_with?(pattern_with_source)
@@ -31,30 +31,6 @@ module Bridgetown
31
31
  ).convert(input.to_s)
32
32
  end
33
33
 
34
- # TODO: This should be removed, there is no Sass converter
35
- # Convert a Sass string into CSS output.
36
- #
37
- # input - The Sass String to convert.
38
- #
39
- # Returns the CSS formatted String.
40
- def sassify(input)
41
- @context.registers[:site].find_converter_instance(
42
- Bridgetown::Converters::Sass
43
- ).convert(input)
44
- end
45
-
46
- # TODO: This should be removed, there is no Scss converter
47
- # Convert a Scss string into CSS output.
48
- #
49
- # input - The Scss String to convert.
50
- #
51
- # Returns the CSS formatted String.
52
- def scssify(input)
53
- @context.registers[:site].find_converter_instance(
54
- Bridgetown::Converters::Scss
55
- ).convert(input)
56
- end
57
-
58
34
  # Slugify a filename or title.
59
35
  #
60
36
  # input - The filename or title to slugify.
@@ -132,7 +108,7 @@ module Bridgetown
132
108
  script += "function(c){{var j=c.charCodeAt(0);if((j>=33)&&(j<=126)){"
133
109
  script += "return String.fromCharCode(33+((j+ 14)%94));}"
134
110
  script += "else{return String.fromCharCode(j);}}}));</script>"
135
- script
111
+ script.html_safe
136
112
  end
137
113
 
138
114
  # Replace any whitespace in the input string with a single space
@@ -3,6 +3,8 @@
3
3
  module Bridgetown
4
4
  module Filters
5
5
  module URLFilters
6
+ extend self
7
+
6
8
  # Produces an absolute URL based on site.url and site.baseurl.
7
9
  #
8
10
  # input - the URL to make absolute.
@@ -35,6 +37,16 @@ module Bridgetown
35
37
  input.sub(%r!/index\.html?$!, "/")
36
38
  end
37
39
 
40
+ # Strips the extension (if present) off a path/URL
41
+ #
42
+ # @param input [Object] value which responds to `to_s`
43
+ # @return [String]
44
+ def strip_extname(input)
45
+ Pathname.new(input.to_s).yield_self do |path|
46
+ path.dirname + path.basename(".*")
47
+ end.to_s
48
+ end
49
+
38
50
  private
39
51
 
40
52
  def compute_absolute_url(input)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ # TODO: to be retired once the Resource engine is made official
4
5
  class Page
5
6
  include DataAccessible
6
7
  include LayoutPlaceable
@@ -44,7 +45,7 @@ module Bridgetown
44
45
  end
45
46
 
46
47
  process(name)
47
- read_yaml(PathManager.join(base, dir), name)
48
+ read_yaml(File.join(base, dir), name)
48
49
 
49
50
  data.default_proc = proc do |_, key|
50
51
  site.frontmatter_defaults.find(relative_path, type, key.to_s)
@@ -133,7 +133,7 @@ module Bridgetown
133
133
  sorted_plugin_files.each do |plugin_file|
134
134
  self.class.add_registered_plugin plugin_file
135
135
  end
136
- Bridgetown::External.require_with_graceful_fail(sorted_plugin_files)
136
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail(sorted_plugin_files)
137
137
  end
138
138
  end
139
139
 
@@ -98,7 +98,7 @@ module Bridgetown
98
98
  def retrieve_dirs(_base, dir, dot_dirs)
99
99
  dot_dirs.each do |file|
100
100
  dir_path = site.in_source_dir(dir, file)
101
- rel_path = PathManager.join(dir, file)
101
+ rel_path = File.join(dir, file)
102
102
  @site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path
103
103
  end
104
104
  end
@@ -124,12 +124,14 @@ module Bridgetown
124
124
  # Retrieve all the static files from the current directory,
125
125
  # add them to the site and sort them.
126
126
  #
127
- # dir - The directory retrieve the static files from.
128
- # dot_static_files - The static files in the dir.
129
- #
130
- # Returns nothing.
131
- def retrieve_static_files(dir, dot_static_files)
132
- site.static_files.concat(StaticFileReader.new(site, dir).read(dot_static_files))
127
+ # @param dir [String] The directory retrieve the static files from.
128
+ # @param files [Array<String>] The static files in the dir.
129
+ def retrieve_static_files(dir, files)
130
+ site.static_files.concat(
131
+ files.map do |file|
132
+ StaticFile.new(site, site.source, dir, file)
133
+ end
134
+ )
133
135
  end
134
136
 
135
137
  # Filter out any files/directories that are hidden or backup files (start
@@ -197,7 +199,7 @@ module Bridgetown
197
199
  if Utils.has_yaml_header?(entry_path)
198
200
  site.pages.concat(PageReader.new(site, dir).read(file))
199
201
  else
200
- site.static_files.concat(StaticFileReader.new(site, dir).read(file))
202
+ retrieve_static_files(dir, file)
201
203
  end
202
204
  end
203
205
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ # TODO: to be retired once the Resource engine is made official
4
5
  class DataReader
5
6
  attr_reader :site, :content
6
7
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ # TODO: to be retired once the Resource engine is made official
4
5
  class PageReader
5
6
  attr_reader :site, :dir, :unfiltered_content
6
7
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ # TODO: to be retired once the Resource engine is made official
4
5
  class PostReader
5
6
  attr_reader :site, :unfiltered_content
6
7
 
@@ -47,7 +48,7 @@ module Bridgetown
47
48
  # Process as Document
48
49
  Document.new(path,
49
50
  site: @site,
50
- collection: @site.posts)
51
+ collection: @site.collections.posts)
51
52
  else
52
53
  # Process as Static File
53
54
  read_static_file(
@@ -66,7 +67,7 @@ module Bridgetown
66
67
  site.source,
67
68
  relative_dir,
68
69
  File.basename(full_path),
69
- @site.posts
70
+ @site.collections.posts
70
71
  )
71
72
  end
72
73
 
@@ -96,9 +97,9 @@ module Bridgetown
96
97
  return false unless processable?(item)
97
98
 
98
99
  if item.is_a?(Document)
99
- site.posts.docs << item
100
+ site.collections.posts.docs << item
100
101
  elsif item.is_a?(StaticFile)
101
- site.posts.static_files << item
102
+ site.collections.posts.static_files << item
102
103
  site.static_files << item
103
104
  end
104
105
 
@@ -11,11 +11,11 @@ module Bridgetown
11
11
  def initialize(post)
12
12
  @post = post
13
13
  @site = post.site
14
- Bridgetown::External.require_with_graceful_fail("classifier-reborn") if site.lsi
14
+ Bridgetown::Utils::RequireGems.require_with_graceful_fail("classifier-reborn") if site.lsi
15
15
  end
16
16
 
17
17
  def build
18
- return [] unless site.posts.docs.size > 1
18
+ return [] unless site.collections.posts.docs.size > 1
19
19
 
20
20
  if site.lsi
21
21
  build_index
@@ -30,7 +30,7 @@ module Bridgetown
30
30
  lsi = ClassifierReborn::LSI.new(auto_rebuild: false)
31
31
  Bridgetown.logger.info("Populating LSI...")
32
32
 
33
- site.posts.docs.each do |x|
33
+ site.collections.posts.docs.each do |x|
34
34
  lsi.add_item(x)
35
35
  end
36
36
 
@@ -46,7 +46,7 @@ module Bridgetown
46
46
  end
47
47
 
48
48
  def most_recent_posts
49
- @most_recent_posts ||= (site.posts.docs.last(11).reverse - [post]).first(10)
49
+ @most_recent_posts ||= (site.collections.posts.docs.last(11).reverse - [post]).first(10)
50
50
  end
51
51
  end
52
52
  end
@@ -32,7 +32,7 @@ module Bridgetown
32
32
 
33
33
  # Strip out file extension and process each segment of a URL to swap out
34
34
  # placeholders such as :categories or :title
35
- url_segments = permalink.sub(%r{\.[^/]*$}, "").split("/")
35
+ url_segments = Bridgetown::Filters::URLFilters.strip_extname(permalink).split("/")
36
36
  new_url = url_segments.map do |segment|
37
37
  segment.starts_with?(":") ? process_segment(segment.sub(%r{^:}, "")) : segment
38
38
  end.select(&:present?).join("/")
@@ -112,7 +112,7 @@ module Bridgetown
112
112
  def locate_include_file(context, file)
113
113
  includes_dirs = tag_includes_dirs(context)
114
114
  includes_dirs.each do |dir|
115
- path = PathManager.join(dir, file)
115
+ path = File.join(dir, file)
116
116
  return path if valid_include_file?(path, dir.to_s)
117
117
  end
118
118
  raise IOError, could_not_locate_message(file, includes_dirs)
@@ -77,14 +77,14 @@ module Bridgetown
77
77
  @context = context
78
78
  site = context.registers[:site]
79
79
 
80
- site.posts.docs.each do |document|
80
+ site.collections.posts.docs.each do |document|
81
81
  return relative_url(document) if @post == document
82
82
  end
83
83
 
84
84
  # New matching method did not match, fall back to old method
85
85
  # with deprecation warning if this matches
86
86
 
87
- site.posts.docs.each do |document|
87
+ site.collections.posts.docs.each do |document|
88
88
  next unless @post.deprecated_equality document
89
89
 
90
90
  Bridgetown::Deprecator.deprecation_message "A call to "\
@@ -4,10 +4,9 @@ module Bridgetown
4
4
  module Utils
5
5
  extend self
6
6
  autoload :Ansi, "bridgetown-core/utils/ansi"
7
+ autoload :RequireGems, "bridgetown-core/utils/require_gems"
7
8
  autoload :RubyExec, "bridgetown-core/utils/ruby_exec"
8
9
  autoload :RubyFrontMatterDSL, "bridgetown-core/utils/ruby_front_matter"
9
- autoload :Platforms, "bridgetown-core/utils/platforms"
10
- autoload :ThreadEvent, "bridgetown-core/utils/thread_event"
11
10
 
12
11
  # Constants for use in #slugify
13
12
  SLUGIFY_MODES = %w(raw default pretty simple ascii latin).freeze
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Utils
5
+ module RequireGems
6
+ class << self
7
+ #
8
+ # Require a gem or file if it's present, otherwise silently fail.
9
+ #
10
+ # names - a string gem name or array of gem names
11
+ #
12
+ def require_if_present(names)
13
+ Array(names).each do |name|
14
+ require name
15
+ rescue LoadError
16
+ Bridgetown.logger.debug "Couldn't load #{name}. Skipping."
17
+ yield(name, version_constraint(name)) if block_given?
18
+ false
19
+ end
20
+ end
21
+
22
+ #
23
+ # The version constraint required to activate a given gem.
24
+ #
25
+ # Returns a String version constraint in a parseable form for
26
+ # RubyGems.
27
+ def version_constraint
28
+ "> 0"
29
+ end
30
+
31
+ #
32
+ # Require a gem or gems. If it's not present, show a very nice error
33
+ # message that explains everything and is much more helpful than the
34
+ # normal LoadError.
35
+ #
36
+ # names - a string gem name or array of gem names
37
+ #
38
+ def require_with_graceful_fail(names)
39
+ Array(names).each do |name|
40
+ Bridgetown.logger.debug "Requiring:", name.to_s
41
+ require name
42
+ rescue LoadError => e
43
+ Bridgetown.logger.error "Dependency Error:", <<~MSG
44
+ Yikes! It looks like you don't have #{name} or one of its dependencies installed.
45
+ In order to use Bridgetown as currently configured, you'll need to install this gem.
46
+
47
+ If you've run Bridgetown with `bundle exec`, ensure that you have included the #{name}
48
+ gem in your Gemfile as well.
49
+
50
+ The full error message from Ruby is: '#{e.message}'
51
+
52
+ If you run into trouble, you can find helpful resources at https://www.bridgetownrb.com/docs/community/
53
+ MSG
54
+ raise Bridgetown::Errors::MissingDependencyException, name
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.21.0.beta1"
4
+ VERSION = "0.21.0.beta2"
5
5
  CODE_NAME = "Broughton Beach"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0.beta1
4
+ version: 0.21.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-25 00:00:00.000000000 Z
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -391,7 +391,6 @@ files:
391
391
  - lib/bridgetown-core/entry_filter.rb
392
392
  - lib/bridgetown-core/errors.rb
393
393
  - lib/bridgetown-core/excerpt.rb
394
- - lib/bridgetown-core/external.rb
395
394
  - lib/bridgetown-core/filters.rb
396
395
  - lib/bridgetown-core/filters/condition_helpers.rb
397
396
  - lib/bridgetown-core/filters/date_filters.rb
@@ -417,7 +416,6 @@ files:
417
416
  - lib/bridgetown-core/model/origin.rb
418
417
  - lib/bridgetown-core/model/repo_origin.rb
419
418
  - lib/bridgetown-core/page.rb
420
- - lib/bridgetown-core/path_manager.rb
421
419
  - lib/bridgetown-core/plugin.rb
422
420
  - lib/bridgetown-core/plugin_manager.rb
423
421
  - lib/bridgetown-core/publisher.rb
@@ -428,7 +426,6 @@ files:
428
426
  - lib/bridgetown-core/readers/page_reader.rb
429
427
  - lib/bridgetown-core/readers/plugin_content_reader.rb
430
428
  - lib/bridgetown-core/readers/post_reader.rb
431
- - lib/bridgetown-core/readers/static_file_reader.rb
432
429
  - lib/bridgetown-core/regenerator.rb
433
430
  - lib/bridgetown-core/related_posts.rb
434
431
  - lib/bridgetown-core/renderer.rb
@@ -455,10 +452,9 @@ files:
455
452
  - lib/bridgetown-core/url.rb
456
453
  - lib/bridgetown-core/utils.rb
457
454
  - lib/bridgetown-core/utils/ansi.rb
458
- - lib/bridgetown-core/utils/platforms.rb
455
+ - lib/bridgetown-core/utils/require_gems.rb
459
456
  - lib/bridgetown-core/utils/ruby_exec.rb
460
457
  - lib/bridgetown-core/utils/ruby_front_matter.rb
461
- - lib/bridgetown-core/utils/thread_event.rb
462
458
  - lib/bridgetown-core/version.rb
463
459
  - lib/bridgetown-core/watcher.rb
464
460
  - lib/site_template/.gitignore
@@ -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