bridgetown-core 1.0.0.alpha2 → 1.0.0.alpha6

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: a735962a1880837aa59641e65afa3985f0ebb091861ae32972d0b875229cfc7d
4
- data.tar.gz: a64d7710c18a4c80805bd7196eacd07387fa1b3061616e8ed2b4de8b9a228871
3
+ metadata.gz: 2dd8600eb037c6f3841fdbc7a9175ecccd0ab4e3c7d1814e914b6954ad4fb832
4
+ data.tar.gz: ca457af17e62de5d71a441b90d9aa8d97136fcd4cc9ecd65a855d8a78bab53b3
5
5
  SHA512:
6
- metadata.gz: 7c136fee524ff82c30ceedcc8ef0ef11fc877ac82066c6bd1d16e0d55cc47391b2b211b72c9f2229d7d83685edb98968e516d2eea09510a1c7c3c4ab0466e6e9
7
- data.tar.gz: 05b65d5c57dfdbd0dcea25ab15875b637868ecd4c69a76a288fe23dd64dc06eb2c3ee6ec980f30b3957888859fbed2e7771a007cf7188cf7572808a17a5c9372
6
+ metadata.gz: 594d6e6de4a514e3eeb439a1ebc3d8936d4bb5027a78063db12c503072fe1c8b6db9d8f3ce6568a95781375d2e0c59dc32faf83fc333e8e9dcd3e95c140e7287
7
+ data.tar.gz: fa2ad70a10323054e8f9ab646dfb92cc37457b53427907888dd8bc47589046feafcdc29730c3d4e6d3eb81cf8cd0be6cebbb692a32d8c3ec200c7a8c7fb80693
@@ -138,7 +138,7 @@ module Bridgetown
138
138
 
139
139
  if @skipped_bundle
140
140
  logger.info "Bundle install skipped.".yellow
141
- logger.info "You will need to run #{"bundle binstub bridgetown-core".cyan} manually."
141
+ logger.info "You will need to run #{"bundle binstubs bridgetown-core".cyan} manually."
142
142
  end
143
143
 
144
144
  logger.info "Yarn install skipped.".yellow if @skipped_yarn
@@ -152,7 +152,7 @@ module Bridgetown
152
152
  Bridgetown.with_unbundled_env do
153
153
  inside(path) do
154
154
  run "bundle install", abort_on_failure: true
155
- run "bundle binstub bridgetown-core"
155
+ run "bundle binstubs bridgetown-core"
156
156
  end
157
157
  end
158
158
  end
@@ -30,8 +30,10 @@ module Bridgetown
30
30
  Bridgetown::Commands::Build.print_startup_message
31
31
  sleep 0.25
32
32
 
33
- unless Bundler.definition.specs.find { |s| s.name == "puma" }
34
- raise "** No Rack-compatible server found **"
33
+ begin
34
+ require("puma/detect")
35
+ rescue LoadError
36
+ raise "** Puma server gem not found. Check your Gemfile and Bundler env? **"
35
37
  end
36
38
 
37
39
  options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
@@ -40,6 +42,12 @@ module Bridgetown
40
42
  # Load Bridgetown configuration into thread memory
41
43
  bt_options = configuration_with_overrides(options)
42
44
 
45
+ if Bridgetown.env.development? && !options["url"]
46
+ scheme = bt_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
47
+ port = bt_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
48
+ bt_options.url = "#{scheme}://localhost:#{port}"
49
+ end
50
+
43
51
  puma_pid =
44
52
  Process.fork do
45
53
  require "puma/cli"
@@ -83,12 +91,6 @@ module Bridgetown
83
91
  Process.setproctitle("bridgetown #{Bridgetown::VERSION} [#{File.basename(Dir.pwd)}]")
84
92
 
85
93
  build_args = ["-w"] + ARGV.reject { |arg| arg == "start" }
86
- if Bridgetown.env.development? && !options["url"]
87
- scheme = bt_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
88
- port = bt_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
89
- build_args << "--url"
90
- build_args << "#{scheme}://localhost:#{port}"
91
- end
92
94
  Bridgetown::Commands::Build.start(build_args)
93
95
  rescue StandardError => e
94
96
  Process.kill "SIGINT", puma_pid
@@ -30,7 +30,7 @@ module Bridgetown
30
30
  #
31
31
  # @param ext [String] erb, slim, etc.
32
32
  def renderer_for_ext(ext, &block)
33
- @_tmpl ||= case ext
33
+ @_tmpl ||= case ext.to_s
34
34
  when "erb"
35
35
  include ERBCapture
36
36
  Tilt::ErubiTemplate.new(component_template_path,
@@ -14,10 +14,10 @@ module Bridgetown
14
14
  end
15
15
 
16
16
  def liquid_engine_configured?
17
- data["template_engine"] == "liquid" ||
17
+ data["template_engine"].to_s == "liquid" ||
18
18
  (
19
19
  data["template_engine"].nil? && (
20
- site.config[:template_engine].nil? || site.config[:template_engine] == "liquid"
20
+ site.config[:template_engine].nil? || site.config[:template_engine].to_s == "liquid"
21
21
  )
22
22
  )
23
23
  end
@@ -21,7 +21,6 @@ class Bridgetown::Site
21
21
 
22
22
  configure_cache
23
23
  configure_component_paths
24
- configure_include_paths
25
24
  configure_file_read_opts
26
25
 
27
26
  self.permalink_style = (config["permalink"] || "pretty").to_sym
@@ -176,10 +175,6 @@ class Bridgetown::Site
176
175
  @components_load_paths = plugin_components_load_paths + local_components_load_paths
177
176
  end
178
177
 
179
- def configure_include_paths
180
- @includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s))
181
- end
182
-
183
178
  def configure_file_read_opts
184
179
  self.file_read_opts = {}
185
180
  file_read_opts[:encoding] = config["encoding"] if config["encoding"]
@@ -20,7 +20,6 @@ module Bridgetown
20
20
  "layouts_dir" => "_layouts",
21
21
  "data_dir" => "_data",
22
22
  "components_dir" => "_components",
23
- "includes_dir" => "_includes",
24
23
  "partials_dir" => "_partials",
25
24
  "collections" => {},
26
25
  "taxonomies" => {
@@ -1,5 +1,5 @@
1
1
  [build]
2
- command = "yarn deploy && ./bin/netlify.sh"
2
+ command = "bin/bridgetown deploy && bin/netlify.sh"
3
3
  publish = "output"
4
4
 
5
5
  [build.environment]
@@ -41,4 +41,4 @@
41
41
  [[headers]]
42
42
  for = "/*.(png|jpg|js|css|svg|woff|ttf|eot|ico|woff2)"
43
43
  [headers.values]
44
- Cache-Control = "public, max-age=31536000, s-max-age=31536000"
44
+ Cache-Control = "public, max-age=31536000, s-max-age=31536000"
@@ -110,7 +110,7 @@ module Bridgetown
110
110
  #
111
111
  # @return [String] The converted content.
112
112
  def convert(content, convertible)
113
- return content if convertible.data[:template_engine] != "erb"
113
+ return content if convertible.data[:template_engine].to_s != "erb"
114
114
 
115
115
  erb_view = Bridgetown::ERBView.new(convertible)
116
116
 
@@ -131,10 +131,12 @@ module Bridgetown
131
131
  end
132
132
  end
133
133
 
134
+ # @param ext [String]
135
+ # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
134
136
  def matches(ext, convertible)
135
- if convertible.data[:template_engine] == "erb" ||
137
+ if convertible.data[:template_engine].to_s == "erb" ||
136
138
  (convertible.data[:template_engine].nil? &&
137
- @config[:template_engine] == "erb")
139
+ @config[:template_engine].to_s == "erb")
138
140
  convertible.data[:template_engine] = "erb"
139
141
  return true
140
142
  end
@@ -56,6 +56,8 @@ module Bridgetown
56
56
  # rubocop: enable Metrics/MethodLength
57
57
  # rubocop: enable Metrics/AbcSize
58
58
 
59
+ # @param ext [String]
60
+ # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
59
61
  def matches(ext, convertible)
60
62
  if convertible.render_with_liquid?
61
63
  convertible.data[:template_engine] = "liquid"
@@ -38,9 +38,9 @@ module Bridgetown
38
38
 
39
39
  def read_data_from_builder
40
40
  builder = Kernel.const_get(url.host.gsub(".", "::"))
41
- raise NameError unless builder.respond_to?(:resource_data_for_id)
41
+ raise NameError unless builder.instance_methods.include?(:resource_data_for_id)
42
42
 
43
- builder.resource_data_for_id(id)
43
+ builder.new.resource_data_for_id(id) || raise(NameError)
44
44
  rescue NameError
45
45
  raise(
46
46
  Bridgetown::Errors::FatalException,
@@ -17,6 +17,14 @@ module Bridgetown
17
17
  def self.boot
18
18
  autoload_server_folder(root: Dir.pwd)
19
19
  RodaApp.opts[:bridgetown_preloaded_config] = Bridgetown::Current.preloaded_configuration
20
+ rescue Roda::RodaError => e
21
+ if e.message.include?("sessions plugin :secret option")
22
+ raise Bridgetown::Errors::InvalidConfigurationError,
23
+ "The Roda sessions plugin can't find a valid secret. Run `bin/bridgetown secret'" \
24
+ " and put the key in a ENV var you can use to configure the session in `roda_app.rb'"
25
+ end
26
+
27
+ raise e
20
28
  end
21
29
 
22
30
  def self.autoload_server_folder(root:)
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ desc "Generate a secret key for use in sessions, token generation, and beyond"
4
+ task :secret do
5
+ require "securerandom"
6
+ puts SecureRandom.hex(64) # rubocop:disable Bridgetown/NoPutsAllowed
7
+ end
8
+
3
9
  namespace :frontend do
4
10
  desc "Run frontend bundler independently"
5
11
  task :watcher, :sidecar do |_task, args|
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "1.0.0.alpha2"
4
+ VERSION = "1.0.0.alpha6"
5
5
  CODE_NAME = "Pearl"
6
6
  end
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html lang="en">
2
+ <html lang="{{ site.locale }}">
3
3
  <head>
4
4
  {% render "head", metadata: site.metadata, title: page.title %}
5
5
  </head>
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: 1.0.0.alpha2
4
+ version: 1.0.0.alpha6
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-10-16 00:00:00.000000000 Z
11
+ date: 2021-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -476,7 +476,6 @@ files:
476
476
  - lib/bridgetown-core/tags/class_map.rb
477
477
  - lib/bridgetown-core/tags/find.rb
478
478
  - lib/bridgetown-core/tags/highlight.rb
479
- - lib/bridgetown-core/tags/include.rb
480
479
  - lib/bridgetown-core/tags/link.rb
481
480
  - lib/bridgetown-core/tags/live_reload_dev_js.rb
482
481
  - lib/bridgetown-core/tags/post_url.rb
@@ -1,216 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bridgetown
4
- module Tags
5
- class IncludeTag < Liquid::Tag
6
- class << self
7
- attr_accessor :deprecation_message_shown
8
- end
9
-
10
- VALID_SYNTAX = %r!
11
- ([\w-]+)\s*=\s*
12
- (?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w.-]+))
13
- !x.freeze
14
-
15
- # rubocop:disable Lint/MixedRegexpCaptureTypes
16
- VARIABLE_SYNTAX = %r!
17
- (?<variable>[^{]*(\{\{\s*[\w\-.]+\s*(\|.*)?\}\}[^\s{}]*)+)
18
- (?<params>.*)
19
- !mx.freeze
20
- # rubocop:enable Lint/MixedRegexpCaptureTypes
21
-
22
- FULL_VALID_SYNTAX = %r!\A\s*(?:#{VALID_SYNTAX}(?=\s|\z)\s*)*\z!.freeze
23
- VALID_FILENAME_CHARS = %r!^[\w/.-]+$!.freeze
24
- INVALID_SEQUENCES = %r![./]{2,}!.freeze
25
-
26
- def initialize(tag_name, markup, tokens)
27
- super
28
-
29
- unless self.class.deprecation_message_shown
30
- Bridgetown.logger.warn "NOTICE: the {% include %} tag is deprecated and" \
31
- " will be removed in Bridgetown 1.0. You should" \
32
- " use the {% render %} tag instead."
33
- self.class.deprecation_message_shown = true
34
- end
35
-
36
- matched = markup.strip.match(VARIABLE_SYNTAX)
37
- if matched
38
- @file = matched["variable"].strip
39
- @params = matched["params"].strip
40
- else
41
- @file, @params = markup.strip.split(%r!\s+!, 2)
42
- end
43
- validate_params if @params
44
- @tag_name = tag_name
45
- end
46
-
47
- def syntax_example
48
- "{% #{@tag_name} file.ext param='value' param2='value' %}"
49
- end
50
-
51
- def parse_params(context)
52
- params = {}
53
- markup = @params
54
-
55
- while (match = VALID_SYNTAX.match(markup))
56
- markup = markup[match.end(0)..-1]
57
-
58
- value = if match[2]
59
- match[2].gsub('\\"', '"')
60
- elsif match[3]
61
- match[3].gsub("\\'", "'")
62
- elsif match[4]
63
- context[match[4]]
64
- end
65
-
66
- params[match[1]] = value
67
- end
68
- params
69
- end
70
-
71
- def validate_file_name(file)
72
- return unless INVALID_SEQUENCES.match?(file) || !VALID_FILENAME_CHARS.match?(file)
73
-
74
- raise ArgumentError, <<~MSG
75
- Invalid syntax for include tag. File contains invalid characters or sequences:
76
-
77
- #{file}
78
-
79
- Valid syntax:
80
-
81
- #{syntax_example}
82
-
83
- MSG
84
- end
85
-
86
- def validate_params
87
- return if FULL_VALID_SYNTAX.match?(@params)
88
-
89
- raise ArgumentError, <<~MSG
90
- Invalid syntax for include tag:
91
-
92
- #{@params}
93
-
94
- Valid syntax:
95
-
96
- #{syntax_example}
97
-
98
- MSG
99
- end
100
-
101
- # Grab file read opts in the context
102
- def file_read_opts(context)
103
- context.registers[:site].file_read_opts
104
- end
105
-
106
- # Render the variable if required
107
- def render_variable(context)
108
- Liquid::Template.parse(@file).render(context) if VARIABLE_SYNTAX.match?(@file)
109
- end
110
-
111
- def tag_includes_dirs(context)
112
- context.registers[:site].includes_load_paths.freeze
113
- end
114
-
115
- def locate_include_file(context, file)
116
- includes_dirs = tag_includes_dirs(context)
117
- includes_dirs.each do |dir|
118
- path = File.join(dir, file)
119
- return path if valid_include_file?(path, dir.to_s)
120
- end
121
- raise IOError, could_not_locate_message(file, includes_dirs)
122
- end
123
-
124
- def render(context)
125
- file = render_variable(context) || @file
126
- validate_file_name(file)
127
-
128
- path = locate_include_file(context, file)
129
- return unless path
130
-
131
- partial = load_cached_partial(path, context)
132
-
133
- context.stack do
134
- context["include"] = parse_params(context) if @params
135
- begin
136
- partial.render!(context)
137
- rescue Liquid::Error => e
138
- e.template_name = path
139
- e.markup_context = "included " if e.markup_context.nil?
140
- raise e
141
- end
142
- end
143
- end
144
-
145
- def load_cached_partial(path, context)
146
- context.registers[:cached_partials] ||= {}
147
- cached_partial = context.registers[:cached_partials]
148
-
149
- if cached_partial.key?(path)
150
- cached_partial[path]
151
- else
152
- unparsed_file = context.registers[:site]
153
- .liquid_renderer
154
- .file(path)
155
- begin
156
- cached_partial[path] = unparsed_file.parse(read_file(path, context))
157
- rescue Liquid::Error => e
158
- e.template_name = path
159
- e.markup_context = "included " if e.markup_context.nil?
160
- raise e
161
- end
162
- end
163
- end
164
-
165
- def valid_include_file?(path, _dir)
166
- File.file?(path)
167
- end
168
-
169
- def realpath_prefixed_with?(path, dir)
170
- File.exist?(path) && File.realpath(path).start_with?(dir)
171
- rescue StandardError
172
- false
173
- end
174
-
175
- # This method allows to modify the file content by inheriting from the class.
176
- def read_file(file, context)
177
- File.read(file, **file_read_opts(context))
178
- end
179
-
180
- private
181
-
182
- def could_not_locate_message(file, includes_dirs)
183
- "Could not locate the included file '#{file}' in any of #{includes_dirs}." \
184
- " Ensure it exists in one of those directories."
185
- end
186
- end
187
-
188
- class IncludeRelativeTag < IncludeTag
189
- def tag_includes_dirs(context)
190
- Array(page_path(context)).freeze
191
- end
192
-
193
- def page_path(context)
194
- if context.registers[:page].nil?
195
- context.registers[:site].source
196
- else
197
- site = context.registers[:site]
198
- page_payload = context.registers[:page]
199
- resource_path = \
200
- if page_payload["collection"].nil?
201
- page_payload["path"]
202
- else
203
- File.join(site.config["collections_dir"], page_payload["path"])
204
- end
205
- # rubocop:disable Performance/DeleteSuffix
206
- resource_path.sub!(%r!/#excerpt\z!, "")
207
- # rubocop:enable Performance/DeleteSuffix
208
- site.in_source_dir File.dirname(resource_path)
209
- end
210
- end
211
- end
212
- end
213
- end
214
-
215
- Liquid::Template.register_tag("include", Bridgetown::Tags::IncludeTag)
216
- Liquid::Template.register_tag("include_relative", Bridgetown::Tags::IncludeRelativeTag)