bridgetown-core 0.15.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +14 -0
  3. data/bridgetown-core.gemspec +4 -1
  4. data/lib/bridgetown-core.rb +8 -2
  5. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -1
  6. data/lib/bridgetown-core/commands/console.rb +4 -4
  7. data/lib/bridgetown-core/concerns/data_accessible.rb +19 -0
  8. data/lib/bridgetown-core/concerns/layout_placeable.rb +17 -0
  9. data/lib/bridgetown-core/concerns/liquid_renderable.rb +20 -0
  10. data/lib/bridgetown-core/concerns/publishable.rb +10 -0
  11. data/lib/bridgetown-core/concerns/site/configurable.rb +66 -31
  12. data/lib/bridgetown-core/concerns/site/content.rb +90 -31
  13. data/lib/bridgetown-core/concerns/site/extensible.rb +15 -12
  14. data/lib/bridgetown-core/concerns/site/localizable.rb +20 -0
  15. data/lib/bridgetown-core/concerns/site/processable.rb +14 -12
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +21 -2
  17. data/lib/bridgetown-core/concerns/site/writable.rb +16 -2
  18. data/lib/bridgetown-core/concerns/validatable.rb +59 -0
  19. data/lib/bridgetown-core/configuration.rb +10 -3
  20. data/lib/bridgetown-core/converter.rb +34 -0
  21. data/lib/bridgetown-core/converters/erb_templates.rb +78 -0
  22. data/lib/bridgetown-core/converters/markdown.rb +6 -23
  23. data/lib/bridgetown-core/converters/smartypants.rb +0 -10
  24. data/lib/bridgetown-core/document.rb +11 -55
  25. data/lib/bridgetown-core/drops/site_drop.rb +1 -1
  26. data/lib/bridgetown-core/errors.rb +2 -0
  27. data/lib/bridgetown-core/excerpt.rb +1 -6
  28. data/lib/bridgetown-core/filters.rb +11 -48
  29. data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
  30. data/lib/bridgetown-core/frontmatter_defaults.rb +17 -0
  31. data/lib/bridgetown-core/layout.rb +24 -1
  32. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -1
  33. data/lib/bridgetown-core/page.rb +41 -26
  34. data/lib/bridgetown-core/plugin_manager.rb +10 -2
  35. data/lib/bridgetown-core/reader.rb +1 -0
  36. data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
  37. data/lib/bridgetown-core/readers/data_reader.rb +4 -3
  38. data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
  39. data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
  40. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  41. data/lib/bridgetown-core/readers/post_reader.rb +1 -0
  42. data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
  43. data/lib/bridgetown-core/regenerator.rb +1 -1
  44. data/lib/bridgetown-core/renderer.rb +40 -14
  45. data/lib/bridgetown-core/ruby_template_view.rb +113 -0
  46. data/lib/bridgetown-core/site.rb +2 -0
  47. data/lib/bridgetown-core/tags/class_map.rb +90 -0
  48. data/lib/bridgetown-core/tags/find.rb +86 -0
  49. data/lib/bridgetown-core/tags/t.rb +14 -0
  50. data/lib/bridgetown-core/tags/webpack_path.rb +19 -22
  51. data/lib/bridgetown-core/utils.rb +55 -2
  52. data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
  53. data/lib/bridgetown-core/version.rb +2 -2
  54. data/lib/site_template/src/_layouts/{default.html → default.liquid} +0 -0
  55. data/lib/site_template/src/_layouts/{home.html → home.liquid} +0 -0
  56. data/lib/site_template/src/_layouts/{page.html → page.liquid} +0 -0
  57. data/lib/site_template/src/_layouts/{post.html → post.liquid} +0 -0
  58. metadata +64 -10
  59. data/lib/bridgetown-core/concerns/convertible.rb +0 -235
@@ -1,235 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Convertible provides methods for converting a pagelike item
4
- # from a certain type of markup into actual content
5
- #
6
- # Requires
7
- # self.site -> Bridgetown::Site
8
- # self.content
9
- # self.content=
10
- # self.data=
11
- # self.ext=
12
- # self.output=
13
- # self.name
14
- # self.path
15
- # self.type -> :page or :post
16
-
17
- module Bridgetown
18
- module Convertible
19
- # Returns the contents as a String.
20
- def to_s
21
- content || ""
22
- end
23
-
24
- # Whether the file is published or not, as indicated in YAML front-matter
25
- def published?
26
- !(data.key?("published") && data["published"] == false)
27
- end
28
-
29
- # Read the YAML frontmatter.
30
- #
31
- # base - The String path to the dir containing the file.
32
- # name - The String filename of the file.
33
- # opts - optional parameter to File.read, default at site configs
34
- #
35
- # Returns nothing.
36
- # rubocop:disable Metrics/AbcSize
37
- def read_yaml(base, name, opts = {})
38
- filename = File.join(base, name)
39
-
40
- begin
41
- self.content = File.read(@path || site.in_source_dir(base, name),
42
- **Utils.merged_file_read_opts(site, opts))
43
- if content =~ Document::YAML_FRONT_MATTER_REGEXP
44
- self.content = $POSTMATCH
45
- self.data = SafeYAML.load(Regexp.last_match(1))&.with_indifferent_access
46
- end
47
- rescue Psych::SyntaxError => e
48
- Bridgetown.logger.warn "YAML Exception reading #{filename}: #{e.message}"
49
- raise e if site.config["strict_front_matter"]
50
- rescue StandardError => e
51
- Bridgetown.logger.warn "Error reading file #{filename}: #{e.message}"
52
- raise e if site.config["strict_front_matter"]
53
- end
54
-
55
- self.data ||= ActiveSupport::HashWithIndifferentAccess.new
56
-
57
- validate_data! filename
58
- validate_permalink! filename
59
-
60
- self.data
61
- end
62
- # rubocop:enable Metrics/AbcSize
63
-
64
- def validate_data!(filename)
65
- unless self.data.is_a?(Hash)
66
- raise Errors::InvalidYAMLFrontMatterError,
67
- "Invalid YAML front matter in #{filename}"
68
- end
69
- end
70
-
71
- def validate_permalink!(filename)
72
- if self.data["permalink"]&.to_s&.empty?
73
- raise Errors::InvalidPermalinkError, "Invalid permalink in #{filename}"
74
- end
75
- end
76
-
77
- # TODO: this method never seems to get called...why's it here?
78
- # Transform the contents based on the content type.
79
- #
80
- # Returns the transformed contents.
81
- def transform
82
- _renderer.convert(content)
83
- end
84
-
85
- # Determine the extension depending on content_type.
86
- #
87
- # Returns the String extension for the output file.
88
- # e.g. ".html" for an HTML output file.
89
- def output_ext
90
- _renderer.output_ext
91
- end
92
-
93
- # Determine which converter to use based on this convertible's
94
- # extension.
95
- #
96
- # Returns the Converter instance.
97
- def converters
98
- _renderer.converters
99
- end
100
-
101
- # Render Liquid in the content
102
- #
103
- # content - the raw Liquid content to render
104
- # payload - the payload for Liquid
105
- # info - the info for Liquid
106
- #
107
- # Returns the converted content
108
- def render_liquid(content, payload, info, path)
109
- _renderer.render_liquid(content, payload, info, path)
110
- end
111
-
112
- # Convert this Convertible's data to a Hash suitable for use by Liquid.
113
- #
114
- # Returns the Hash representation of this Convertible.
115
- def to_liquid(attrs = nil)
116
- further_data = \
117
- (attrs || self.class::ATTRIBUTES_FOR_LIQUID).each_with_object({}) do |attribute, hsh|
118
- hsh[attribute] = send(attribute)
119
- end
120
-
121
- defaults = site.frontmatter_defaults.all(relative_path, type)
122
- Utils.deep_merge_hashes defaults, Utils.deep_merge_hashes(data, further_data)
123
- end
124
-
125
- # The type of a document,
126
- # i.e., its classname downcase'd and to_sym'd.
127
- #
128
- # Returns the type of self.
129
- def type
130
- :pages if is_a?(Page)
131
- end
132
-
133
- # returns the owner symbol for hook triggering
134
- def hook_owner
135
- :pages if is_a?(Page)
136
- end
137
-
138
- # TODO: Depricated
139
- # Used to determine CoffeeScript and Sass/SCSS files.
140
- def asset_file?
141
- false
142
- end
143
-
144
- # Determine whether the file should be rendered with Liquid.
145
- #
146
- # Returns true if the file has Liquid Tags or Variables, false otherwise.
147
- def render_with_liquid?
148
- return false if data["render_with_liquid"] == false
149
-
150
- Bridgetown::Utils.has_liquid_construct?(content)
151
- end
152
-
153
- # Determine whether the file should be placed into layouts.
154
- #
155
- # Returns false if the document is an asset file or if the front matter
156
- # specifies `layout: none`
157
- def place_in_layout?
158
- !(asset_file? || no_layout?)
159
- end
160
-
161
- # Checks if the layout specified in the document actually exists
162
- #
163
- # layout - the layout to check
164
- #
165
- # Returns true if the layout is invalid, false if otherwise
166
- def invalid_layout?(layout)
167
- !data["layout"].nil? && layout.nil? && !(is_a? Bridgetown::Excerpt)
168
- end
169
-
170
- # Recursively render layouts
171
- #
172
- # layouts - a list of the layouts
173
- # payload - the payload for Liquid
174
- # info - the info for Liquid
175
- #
176
- # Returns nothing
177
- def render_all_layouts(layouts, payload, info)
178
- _renderer.layouts = layouts
179
- self.output = _renderer.place_in_layouts(output, payload, info)
180
- ensure
181
- @_renderer = nil # this will allow the modifications above to disappear
182
- end
183
-
184
- # Add any necessary layouts to this convertible document.
185
- #
186
- # payload - The site payload Drop or Hash.
187
- # layouts - A Hash of {"name" => "layout"}.
188
- #
189
- # Returns nothing.
190
- def do_layout(payload, layouts)
191
- _renderer.tap do |renderer|
192
- renderer.layouts = layouts
193
- renderer.payload = payload
194
- end.run
195
- ensure
196
- @_renderer = nil # this will allow the modifications above to disappear
197
- end
198
-
199
- # Write the generated page file to the destination directory.
200
- #
201
- # dest - The String path to the destination dir.
202
- #
203
- # Returns nothing.
204
- def write(dest)
205
- path = destination(dest)
206
- FileUtils.mkdir_p(File.dirname(path))
207
- Bridgetown.logger.debug "Writing:", path
208
- File.write(path, output, mode: "wb")
209
- Bridgetown::Hooks.trigger hook_owner, :post_write, self
210
- end
211
-
212
- # Accessor for data properties by Liquid.
213
- #
214
- # property - The String name of the property to retrieve.
215
- #
216
- # Returns the String value or nil if the property isn't included.
217
- def [](property)
218
- if self.class::ATTRIBUTES_FOR_LIQUID.include?(property)
219
- send(property)
220
- else
221
- data[property]
222
- end
223
- end
224
-
225
- private
226
-
227
- def _renderer
228
- @_renderer ||= Bridgetown::Renderer.new(site, self)
229
- end
230
-
231
- def no_layout?
232
- data["layout"] == "none"
233
- end
234
- end
235
- end