bridgetown-core 0.16.0.beta1 → 0.16.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25a57f1cf4e0a06e347edf5c97c78a168bc56f5efab6fdcf7f55a78ac491a3de
4
- data.tar.gz: 96f00f4e411b8f46467d3f8ff6ecb153c07a34f5496f4109361afdfe8d7493c0
3
+ metadata.gz: d9c23ef7da53e1f746ee14540f1f370ad6edea81667e314e9ff9e4c032c8c40c
4
+ data.tar.gz: f8ef26737713ef23c95a5b61407b51e791c266a0eef766ab4ca07fd9ad9e39bc
5
5
  SHA512:
6
- metadata.gz: 378534362fb45c10c4aef9600771e10d13d07f827309ee2dd2395ff5c60a9b36c1e1b309e48274de3ef09ac9d16178ad563d49da437535961ba27844c86020d0
7
- data.tar.gz: dda52cf9adc2768b57dc93677babdd63b5d1e500a8fbfe7c69f0dcb719701f3b986ae740d3fca703932f346b172b23e0c8561549a7f1dddad7b3b97b3605e535
6
+ metadata.gz: 4fd1626a1708c19486e34a74deeea3c5f2659eb7c96dc7ff0444d464347e4b83e410e36b7b75da727d0120399e01e9f9b11915f6a7f601bb89159bf5bcc863e5
7
+ data.tar.gz: f087e6a3c5d2990f514f9ebfa33cf6a7654d0ab2f22ea09f0411dee72caaed12684642a43a5fa4b55790544814f6a599fe663ccc91390849d3acb51ec58d9b22
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.add_runtime_dependency("addressable", "~> 2.4")
36
36
  s.add_runtime_dependency("awesome_print", "~> 1.8")
37
37
  s.add_runtime_dependency("colorator", "~> 1.0")
38
+ s.add_runtime_dependency("erubi", "~> 1.9")
38
39
  s.add_runtime_dependency("faraday", "~> 1.0")
39
40
  s.add_runtime_dependency("faraday_middleware", "~> 1.0")
40
41
  s.add_runtime_dependency("i18n", "~> 1.0")
@@ -11,6 +11,7 @@ module Bridgetown
11
11
  GITHUB_REGEX = %r!https://github\.com!.freeze
12
12
  GITHUB_TREE_REGEX = %r!#{GITHUB_REGEX}/.*/.*/tree/.*/?!.freeze
13
13
  GITHUB_BLOB_REGEX = %r!#{GITHUB_REGEX}/.*/.*/blob/!.freeze
14
+ GITHUB_REPO_REGEX = %r!github\.com/(.*?/[^/]*)!.freeze
14
15
 
15
16
  def create_builder(filename, data = nil)
16
17
  say_status :create_builder, filename
@@ -114,7 +115,7 @@ module Bridgetown
114
115
  elsif github_blob_match
115
116
  new_url.sub("/blob/", "/")
116
117
  else
117
- "#{new_url}/master"
118
+ "#{new_url}/#{Bridgetown::Utils.default_github_branch_name(arg)}"
118
119
  end
119
120
  else
120
121
  arg
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tilt/erb"
4
- require "active_support/core_ext/hash/keys"
3
+ require "tilt/erubi"
4
+ require "erubi/capture_end"
5
5
 
6
6
  module Bridgetown
7
7
  class ERBView < RubyTemplateView
8
- include ERB::Util
8
+ def h(input)
9
+ Erubi.h(input)
10
+ end
9
11
 
10
12
  def partial(partial_name, options = {})
11
13
  options.merge!(options[:locals]) if options[:locals]
@@ -14,10 +16,10 @@ module Bridgetown
14
16
  partial_segments.last.sub!(%r!^!, "_")
15
17
  partial_name = partial_segments.join("/")
16
18
 
17
- Tilt::ERBTemplate.new(
19
+ Tilt::ErubiTemplate.new(
18
20
  site.in_source_dir(site.config[:partials_dir], "#{partial_name}.erb"),
19
- trim: "<>-",
20
- outvar: "@_erbout"
21
+ outvar: "@_erbout",
22
+ engine_class: Erubi::CaptureEndEngine
21
23
  ).render(self, options)
22
24
  end
23
25
 
@@ -32,21 +34,36 @@ module Bridgetown
32
34
  md_output = converter.convert(content).strip
33
35
  @_erbout << md_output
34
36
  end
37
+
38
+ def capture
39
+ previous_buffer_state = @_erbout
40
+ @_erbout = +""
41
+ result = yield
42
+ @_erbout = previous_buffer_state
43
+
44
+ result
45
+ end
35
46
  end
36
47
 
37
48
  module Converters
38
49
  class ERBTemplates < Converter
39
50
  input :erb
40
51
 
41
- # Logic to do the content conversion.
52
+ # Logic to do the ERB content conversion.
42
53
  #
43
- # content - String content of file (without front matter).
54
+ # @param content [String] Content of the file (without front matter).
55
+ # @params convertible [Bridgetown::Page, Bridgetown::Document, Bridgetown::Layout]
56
+ # The instantiated object which is processing the file.
44
57
  #
45
- # Returns a String of the converted content.
58
+ # @return [String] The converted content.
46
59
  def convert(content, convertible)
47
60
  erb_view = Bridgetown::ERBView.new(convertible)
48
61
 
49
- erb_renderer = Tilt::ERBTemplate.new(trim: "<>-", outvar: "@_erbout") { content }
62
+ erb_renderer = Tilt::ErubiTemplate.new(
63
+ convertible.relative_path,
64
+ outvar: "@_erbout",
65
+ engine_class: Erubi::CaptureEndEngine
66
+ ) { content }
50
67
 
51
68
  if convertible.is_a?(Bridgetown::Layout)
52
69
  erb_renderer.render(erb_view) do
@@ -68,12 +68,20 @@ module Bridgetown
68
68
  # If that exact package hasn't been installed, execute yarn add
69
69
  #
70
70
  # Returns nothing.
71
- def self.install_yarn_dependencies(required_gems)
71
+ def self.install_yarn_dependencies(required_gems, single_gemname = nil)
72
72
  return unless File.exist?("package.json")
73
73
 
74
74
  package_json = JSON.parse(File.read("package.json"))
75
75
 
76
- required_gems.each do |loaded_gem|
76
+ gems_to_search = if single_gemname
77
+ required_gems.select do |loaded_gem|
78
+ loaded_gem.to_spec&.name == single_gemname.to_s
79
+ end
80
+ else
81
+ required_gems
82
+ end
83
+
84
+ gems_to_search.each do |loaded_gem|
77
85
  yarn_dependency = find_yarn_dependency(loaded_gem)
78
86
  next unless add_yarn_dependency?(yarn_dependency, package_json)
79
87
 
@@ -1,11 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "digest"
4
+ require "active_support/core_ext/hash/keys"
4
5
 
5
6
  module Bridgetown
6
7
  class RubyTemplateView
7
8
  class Helpers
8
9
  include Bridgetown::Filters
10
+
11
+ Context = Struct.new(:registers)
12
+
13
+ def initialize(site)
14
+ @site = site
15
+
16
+ # duck typing for Liquid context
17
+ @context = Context.new({ site: @site })
18
+ end
19
+
20
+ def webpack_path(asset_type)
21
+ Bridgetown::Utils.parse_webpack_manifest_file(@site, asset_type.to_s)
22
+ end
9
23
  end
10
24
 
11
25
  attr_reader :layout, :page, :site, :content
@@ -43,7 +57,7 @@ module Bridgetown
43
57
  end
44
58
 
45
59
  def helpers
46
- @helpers ||= Helpers.new
60
+ @helpers ||= Helpers.new(@site)
47
61
  end
48
62
 
49
63
  def method_missing(method, *args, &block)
@@ -5,12 +5,10 @@ module Bridgetown
5
5
  # A helper class to help find the path to webpack asset inside of a webpack
6
6
  # manifest file.
7
7
  class WebpackPath < Liquid::Tag
8
- include Bridgetown::Filters::URLFilters
9
-
10
8
  # @param tag_name [String] Name of the tag
11
9
  # @param asset_type [String] The type of asset to parse (js, css)
12
10
  # @param options [Hash] An options hash
13
- # @return WebpackPath
11
+ # @return [void]
14
12
  # @see {https://www.rdoc.info/github/Shopify/liquid/Liquid/Tag#initialize-instance_method}
15
13
  def initialize(tag_name, asset_type, options)
16
14
  super
@@ -19,12 +17,12 @@ module Bridgetown
19
17
  @asset_type = asset_type.strip
20
18
  end
21
19
 
22
- # Render the contents of a webpack manifest file
23
- # @param context [String] Root directory that contains the manifest file
20
+ # Render an asset path based on the Webpack manifest file
21
+ # @param context [Liquid::Context] Context passed to the tag
24
22
  #
25
23
  # @return [String] Returns "MISSING_WEBPACK_MANIFEST" if the manifest
26
- # file isnt found
27
- # @return [nil] Returns nil if the asset isnt found
24
+ # file isn't found
25
+ # @return [String] Returns a blank string if the asset isn't found
28
26
  # @return [String] Returns the path to the asset if no issues parsing
29
27
  #
30
28
  # @raise [WebpackAssetError] if unable to find css or js in the manifest
@@ -32,40 +30,7 @@ module Bridgetown
32
30
  def render(context)
33
31
  @context = context
34
32
  site = context.registers[:site]
35
-
36
- manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
37
-
38
- parse_manifest_file(manifest_file)
39
- end
40
-
41
- private
42
-
43
- def parse_manifest_file(manifest_file)
44
- return "MISSING_WEBPACK_MANIFEST" unless File.exist?(manifest_file)
45
-
46
- manifest = JSON.parse(File.read(manifest_file))
47
- frontend_path = relative_url("_bridgetown/static")
48
-
49
- known_assets = %w(js css)
50
-
51
- if known_assets.include?(@asset_type)
52
- asset_path = manifest["main.#{@asset_type}"]
53
-
54
- log_webpack_asset_error(@asset_type) if asset_path.nil?
55
-
56
- asset_path = asset_path.split("/").last
57
- return [frontend_path, @asset_type, asset_path].join("/")
58
- end
59
-
60
- Bridgetown.logger.error("Unknown Webpack asset type", @asset_type)
61
- nil
62
- end
63
-
64
- def log_webpack_asset_error(asset_type)
65
- error_message = "There was an error parsing your #{asset_type} files. \
66
- Please check your #{asset_type} for any errors."
67
-
68
- Bridgetown.logger.warn(Errors::WebpackAssetError, error_message)
33
+ Bridgetown::Utils.parse_webpack_manifest_file(site, @asset_type) || ""
69
34
  end
70
35
  end
71
36
  end
@@ -331,6 +331,59 @@ module Bridgetown
331
331
  end
332
332
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
333
333
 
334
+ # Return an asset path based on the Webpack manifest file
335
+ # @param site [Bridgetown::Site] The current site object
336
+ # @param asset_type [String] js or css
337
+ #
338
+ # @return [String] Returns "MISSING_WEBPACK_MANIFEST" if the manifest
339
+ # file isnt found
340
+ # @return [nil] Returns nil if the asset isnt found
341
+ # @return [String] Returns the path to the asset if no issues parsing
342
+ #
343
+ # @raise [WebpackAssetError] if unable to find css or js in the manifest
344
+ # file
345
+ def parse_webpack_manifest_file(site, asset_type)
346
+ manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
347
+ return "MISSING_WEBPACK_MANIFEST" unless File.exist?(manifest_file)
348
+
349
+ manifest = JSON.parse(File.read(manifest_file))
350
+
351
+ known_assets = %w(js css)
352
+ if known_assets.include?(asset_type)
353
+ asset_path = manifest["main.#{asset_type}"]
354
+
355
+ log_webpack_asset_error(asset_type) && return if asset_path.nil?
356
+
357
+ asset_path = asset_path.split("/").last
358
+ return [static_frontend_path(site), asset_type, asset_path].join("/")
359
+ end
360
+
361
+ Bridgetown.logger.error("Unknown Webpack asset type", asset_type)
362
+ nil
363
+ end
364
+
365
+ def static_frontend_path(site)
366
+ path_parts = [site.config["baseurl"].to_s.chomp("/"), "_bridgetown/static"]
367
+ path_parts[0] = "/#{path_parts[0]}" unless path_parts[0].empty?
368
+ Addressable::URI.parse(path_parts.join("/")).normalize.to_s
369
+ end
370
+
371
+ def log_webpack_asset_error(asset_type)
372
+ error_message = "There was an error parsing your #{asset_type} files. \
373
+ Please check your #{asset_type} for any errors."
374
+
375
+ Bridgetown.logger.warn(Errors::WebpackAssetError, error_message)
376
+ end
377
+
378
+ def default_github_branch_name(repo_url)
379
+ repo_match = Bridgetown::Commands::Actions::GITHUB_REPO_REGEX.match(repo_url)
380
+ api_endpoint = "https://api.github.com/repos/#{repo_match[1]}"
381
+ JSON.parse(Faraday.get(api_endpoint).body)["default_branch"] || "master"
382
+ rescue StandardError => e
383
+ Bridgetown.logger.warn("Unable to connect to GitHub API: #{e.message}")
384
+ "master"
385
+ end
386
+
334
387
  private
335
388
 
336
389
  def merge_values(target, overwrite)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.16.0.beta1"
4
+ VERSION = "0.16.0.beta2"
5
5
  CODE_NAME = "Crystal Springs"
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.16.0.beta1
4
+ version: 0.16.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: 2020-07-16 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: erubi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: faraday
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -409,10 +423,10 @@ files:
409
423
  - lib/site_template/src/_components/head.liquid
410
424
  - lib/site_template/src/_components/navbar.liquid
411
425
  - lib/site_template/src/_data/site_metadata.yml
412
- - lib/site_template/src/_layouts/default.html
413
- - lib/site_template/src/_layouts/home.html
414
- - lib/site_template/src/_layouts/page.html
415
- - lib/site_template/src/_layouts/post.html
426
+ - lib/site_template/src/_layouts/default.liquid
427
+ - lib/site_template/src/_layouts/home.liquid
428
+ - lib/site_template/src/_layouts/page.liquid
429
+ - lib/site_template/src/_layouts/post.liquid
416
430
  - lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb
417
431
  - lib/site_template/src/about.md
418
432
  - lib/site_template/src/favicon.ico