bridgetown-core 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +1 -0
- data/lib/bridgetown-core.rb +1 -1
- data/lib/bridgetown-core/concerns/site/content.rb +3 -3
- data/lib/bridgetown-core/concerns/site/processable.rb +2 -2
- data/lib/bridgetown-core/concerns/validatable.rb +2 -2
- data/lib/bridgetown-core/configuration.rb +5 -1
- data/lib/bridgetown-core/document.rb +3 -3
- data/lib/bridgetown-core/filters.rb +8 -0
- data/lib/bridgetown-core/page.rb +8 -2
- data/lib/bridgetown-core/readers/data_reader.rb +3 -3
- data/lib/bridgetown-core/readers/defaults_reader.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +2 -2
- data/lib/bridgetown-core/ruby_template_view.rb +16 -5
- data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
- data/lib/bridgetown-core/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7878e020dc228c491934a986395227f17fa2ca93398ae0f3961a77c4df6e1761
|
4
|
+
data.tar.gz: 73dd2ad473c8525974708393f97f0ce464241fedcc78951186b726ea3435c444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38624e9ea2b7e604b773f2224eec18fdce5e44fc9c9e388c7cefa1ebee6fcee62aa96406ff783a7458a5b3d7a24f45c486a2cc2e925867609a26cb8e30336bb1
|
7
|
+
data.tar.gz: eb46348e312153b95b46b1b5e7fbfca154c4d39c87af62e9b77ccdfacdd43cca640b8adf216c223aeb9f47f92977df48d3550dab1a7a173dac256c92cf89f77f
|
data/bridgetown-core.gemspec
CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
s.add_runtime_dependency("erubi", "~> 1.9")
|
39
39
|
s.add_runtime_dependency("faraday", "~> 1.0")
|
40
40
|
s.add_runtime_dependency("faraday_middleware", "~> 1.0")
|
41
|
+
s.add_runtime_dependency("hash_with_dot_access", "~> 1.0")
|
41
42
|
s.add_runtime_dependency("i18n", "~> 1.0")
|
42
43
|
s.add_runtime_dependency("kramdown", "~> 2.1")
|
43
44
|
s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
|
data/lib/bridgetown-core.rb
CHANGED
@@ -29,8 +29,8 @@ require "csv"
|
|
29
29
|
require "json"
|
30
30
|
|
31
31
|
# 3rd party
|
32
|
-
require "active_support/core_ext/hash/indifferent_access"
|
33
32
|
require "active_support/core_ext/string/inflections"
|
33
|
+
require "hash_with_dot_access"
|
34
34
|
require "pathutil"
|
35
35
|
require "addressable/uri"
|
36
36
|
require "safe_yaml/load"
|
@@ -61,10 +61,10 @@ module Bridgetown
|
|
61
61
|
end
|
62
62
|
|
63
63
|
# Returns the value of +data+["site_metadata"] or creates a new instance of
|
64
|
-
# +
|
64
|
+
# +HashWithDotAccess::Hash+
|
65
65
|
# @return [Hash] Returns a hash of site metadata
|
66
66
|
def metadata
|
67
|
-
data["site_metadata"] ||=
|
67
|
+
data["site_metadata"] ||= HashWithDotAccess::Hash.new
|
68
68
|
end
|
69
69
|
|
70
70
|
# The Hash payload containing site-wide data.
|
@@ -116,7 +116,7 @@ module Bridgetown
|
|
116
116
|
# @see Collection
|
117
117
|
def collections
|
118
118
|
@collections ||= collection_names.each_with_object(
|
119
|
-
|
119
|
+
HashWithDotAccess::Hash.new
|
120
120
|
) do |name, hsh|
|
121
121
|
hsh[name] = Bridgetown::Collection.new(self, name)
|
122
122
|
end
|
@@ -30,10 +30,10 @@ module Bridgetown
|
|
30
30
|
else
|
31
31
|
Time.now
|
32
32
|
end
|
33
|
-
self.layouts =
|
33
|
+
self.layouts = HashWithDotAccess::Hash.new
|
34
34
|
self.pages = []
|
35
35
|
self.static_files = []
|
36
|
-
self.data =
|
36
|
+
self.data = HashWithDotAccess::Hash.new
|
37
37
|
@post_attr_hash = {}
|
38
38
|
@collections = nil
|
39
39
|
@documents = nil
|
@@ -22,7 +22,7 @@ module Bridgetown
|
|
22
22
|
**Utils.merged_file_read_opts(site, opts))
|
23
23
|
if content =~ Document::YAML_FRONT_MATTER_REGEXP
|
24
24
|
self.content = $POSTMATCH
|
25
|
-
self.data = SafeYAML.load(Regexp.last_match(1))&.
|
25
|
+
self.data = SafeYAML.load(Regexp.last_match(1))&.with_dot_access
|
26
26
|
end
|
27
27
|
rescue Psych::SyntaxError => e
|
28
28
|
Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
|
@@ -32,7 +32,7 @@ module Bridgetown
|
|
32
32
|
raise e if site.config["strict_front_matter"]
|
33
33
|
end
|
34
34
|
|
35
|
-
self.data ||=
|
35
|
+
self.data ||= HashWithDotAccess::Hash.new
|
36
36
|
|
37
37
|
validate_data! filename
|
38
38
|
validate_permalink! filename
|
@@ -4,7 +4,7 @@ module Bridgetown
|
|
4
4
|
# TODO: refactor this whole object! Already had to fix obscure
|
5
5
|
# bugs just making minor changes, and all the indirection is
|
6
6
|
# quite hard to decipher. -JW
|
7
|
-
class Configuration <
|
7
|
+
class Configuration < HashWithDotAccess::Hash
|
8
8
|
# Default options. Overridden by values in bridgetown.config.yml.
|
9
9
|
# Strings rather than symbols are used for compatibility with YAML.
|
10
10
|
DEFAULTS = {
|
@@ -311,6 +311,10 @@ module Bridgetown
|
|
311
311
|
raise Bridgetown::Errors::InvalidConfigurationError,
|
312
312
|
"'#{option}' should be set as an array, but was: #{self[option].inspect}."
|
313
313
|
end
|
314
|
+
|
315
|
+
# add _pages to includes set
|
316
|
+
self[:include] << "_pages"
|
317
|
+
|
314
318
|
self
|
315
319
|
end
|
316
320
|
end
|
@@ -63,7 +63,7 @@ module Bridgetown
|
|
63
63
|
# Returns a Hash containing the data. An empty hash is returned if
|
64
64
|
# no data was read.
|
65
65
|
def data
|
66
|
-
@data ||=
|
66
|
+
@data ||= HashWithDotAccess::Hash.new
|
67
67
|
end
|
68
68
|
|
69
69
|
# Merge some data in with this document's data.
|
@@ -170,7 +170,7 @@ module Bridgetown
|
|
170
170
|
#
|
171
171
|
# Returns the permalink or nil if no permalink was set in the data.
|
172
172
|
def permalink
|
173
|
-
data
|
173
|
+
data&.permalink
|
174
174
|
end
|
175
175
|
|
176
176
|
# The computed URL for the document. See `Bridgetown::URL#to_s` for more details.
|
@@ -295,7 +295,7 @@ module Bridgetown
|
|
295
295
|
|
296
296
|
def previous_doc
|
297
297
|
pos = collection.docs.index { |post| post.equal?(self) }
|
298
|
-
collection.docs[pos - 1] if pos
|
298
|
+
collection.docs[pos - 1] if pos&.positive?
|
299
299
|
end
|
300
300
|
|
301
301
|
def trigger_hooks(hook_name, *args)
|
@@ -138,6 +138,14 @@ module Bridgetown
|
|
138
138
|
input.split.length
|
139
139
|
end
|
140
140
|
|
141
|
+
# Calculates the average reading time of the supplied content.
|
142
|
+
# @param input [String] the String of content to analyze.
|
143
|
+
# @return [Float] the number of minutes required to read the content.
|
144
|
+
def reading_time(input, round_to = 0)
|
145
|
+
wpm = @context.registers[:site].config[:reading_time_wpm] || 250
|
146
|
+
(number_of_words(input).to_f / wpm).ceil(round_to)
|
147
|
+
end
|
148
|
+
|
141
149
|
# Join an array of things into a string by separating with commas and the
|
142
150
|
# word "and" for the last one.
|
143
151
|
#
|
data/lib/bridgetown-core/page.rb
CHANGED
@@ -9,7 +9,7 @@ module Bridgetown
|
|
9
9
|
include Validatable
|
10
10
|
|
11
11
|
attr_writer :dir
|
12
|
-
attr_accessor :site, :pager
|
12
|
+
attr_accessor :site, :paginator, :pager
|
13
13
|
attr_accessor :name, :ext, :basename
|
14
14
|
attr_accessor :data, :content, :output
|
15
15
|
|
@@ -121,12 +121,18 @@ module Bridgetown
|
|
121
121
|
# desired placeholder replacements. For details see "url.rb"
|
122
122
|
def url_placeholders
|
123
123
|
{
|
124
|
-
path:
|
124
|
+
path: qualified_pages_path_for_url,
|
125
125
|
basename: basename,
|
126
126
|
output_ext: output_ext,
|
127
127
|
}
|
128
128
|
end
|
129
129
|
|
130
|
+
# Strips _pages prefix off if needed for the url/destination generation
|
131
|
+
# @return [String]
|
132
|
+
def qualified_pages_path_for_url
|
133
|
+
@dir.sub(%r!^/_pages!, "")
|
134
|
+
end
|
135
|
+
|
130
136
|
# Extract information from the page filename.
|
131
137
|
#
|
132
138
|
# name - The String filename of the page file.
|
@@ -6,7 +6,7 @@ module Bridgetown
|
|
6
6
|
|
7
7
|
def initialize(site)
|
8
8
|
@site = site
|
9
|
-
@content =
|
9
|
+
@content = {}
|
10
10
|
@entry_filter = EntryFilter.new(site)
|
11
11
|
end
|
12
12
|
|
@@ -20,7 +20,7 @@ module Bridgetown
|
|
20
20
|
base = site.in_source_dir(dir)
|
21
21
|
read_data_to(base, @content)
|
22
22
|
merge_environment_specific_metadata!
|
23
|
-
@content
|
23
|
+
@content = @content.with_dot_access
|
24
24
|
end
|
25
25
|
|
26
26
|
# Read and parse all .yaml, .yml, .json, .csv and .tsv
|
@@ -44,7 +44,7 @@ module Bridgetown
|
|
44
44
|
if File.directory?(path)
|
45
45
|
read_data_to(
|
46
46
|
path,
|
47
|
-
data[sanitize_filename(entry)] =
|
47
|
+
data[sanitize_filename(entry)] = {}
|
48
48
|
)
|
49
49
|
else
|
50
50
|
key = sanitize_filename(File.basename(entry, ".*"))
|
@@ -249,12 +249,12 @@ module Bridgetown
|
|
249
249
|
)
|
250
250
|
end
|
251
251
|
|
252
|
-
# Set page content to payload and assign
|
252
|
+
# Set page content to payload and assign paginator if document has one.
|
253
253
|
#
|
254
254
|
# Returns nothing
|
255
255
|
def assign_pages!
|
256
256
|
payload["page"] = document.to_liquid
|
257
|
-
payload["paginator"] =
|
257
|
+
payload["paginator"] = document.paginator.to_liquid if document.respond_to?(:paginator)
|
258
258
|
end
|
259
259
|
|
260
260
|
# Set related posts to payload if document is a post.
|
@@ -8,17 +8,27 @@ module Bridgetown
|
|
8
8
|
class Helpers
|
9
9
|
include Bridgetown::Filters
|
10
10
|
|
11
|
+
attr_reader :view, :site
|
12
|
+
|
11
13
|
Context = Struct.new(:registers)
|
12
14
|
|
13
|
-
def initialize(site)
|
15
|
+
def initialize(view, site)
|
16
|
+
@view = view
|
14
17
|
@site = site
|
15
18
|
|
16
19
|
# duck typing for Liquid context
|
17
|
-
@context = Context.new({ site:
|
20
|
+
@context = Context.new({ site: site })
|
18
21
|
end
|
19
22
|
|
20
23
|
def webpack_path(asset_type)
|
21
|
-
Bridgetown::Utils.parse_webpack_manifest_file(
|
24
|
+
Bridgetown::Utils.parse_webpack_manifest_file(site, asset_type.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param pairs [Hash] A hash of key/value pairs.
|
28
|
+
#
|
29
|
+
# @return [String] Space-separated keys where the values are truthy.
|
30
|
+
def class_map(pairs = {})
|
31
|
+
pairs.select { |_key, truthy| truthy }.keys.join(" ")
|
22
32
|
end
|
23
33
|
|
24
34
|
def t(*args)
|
@@ -26,7 +36,7 @@ module Bridgetown
|
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
|
-
attr_reader :layout, :page, :site, :content
|
39
|
+
attr_reader :layout, :page, :paginator, :site, :content
|
30
40
|
|
31
41
|
def initialize(convertible)
|
32
42
|
if convertible.is_a?(Layout)
|
@@ -36,6 +46,7 @@ module Bridgetown
|
|
36
46
|
else
|
37
47
|
@page = convertible
|
38
48
|
end
|
49
|
+
@paginator = page.paginator if page.respond_to?(:paginator)
|
39
50
|
@site = page.site
|
40
51
|
end
|
41
52
|
|
@@ -61,7 +72,7 @@ module Bridgetown
|
|
61
72
|
end
|
62
73
|
|
63
74
|
def helpers
|
64
|
-
@helpers ||= Helpers.new(
|
75
|
+
@helpers ||= Helpers.new(self, site)
|
65
76
|
end
|
66
77
|
|
67
78
|
def method_missing(method, *args, &block)
|
@@ -59,7 +59,7 @@ module Bridgetown
|
|
59
59
|
|
60
60
|
# This is where the magic happens! DON'T BE EVIL!!! ;-)
|
61
61
|
output = obj.instance_eval(ruby_code)
|
62
|
-
output.is_a?(Hash) ? output.
|
62
|
+
output.is_a?(Hash) ? output.with_dot_access : output
|
63
63
|
end
|
64
64
|
end
|
65
65
|
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.17.
|
4
|
+
version: 0.17.1
|
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-
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hash_with_dot_access
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: i18n
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|