bridgetown-core 0.16.0.beta2 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/bridgetown-core.gemspec +2 -1
  4. data/lib/bridgetown-core.rb +45 -29
  5. data/lib/bridgetown-core/collection.rb +5 -1
  6. data/lib/bridgetown-core/commands/apply.rb +2 -2
  7. data/lib/bridgetown-core/commands/console.rb +4 -4
  8. data/lib/bridgetown-core/commands/new.rb +1 -1
  9. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  10. data/lib/bridgetown-core/concerns/liquid_renderable.rb +10 -0
  11. data/lib/bridgetown-core/concerns/site/configurable.rb +24 -22
  12. data/lib/bridgetown-core/concerns/site/content.rb +46 -33
  13. data/lib/bridgetown-core/concerns/site/extensible.rb +14 -13
  14. data/lib/bridgetown-core/concerns/site/localizable.rb +24 -0
  15. data/lib/bridgetown-core/concerns/site/processable.rb +12 -15
  16. data/lib/bridgetown-core/concerns/site/renderable.rb +35 -28
  17. data/lib/bridgetown-core/concerns/site/writable.rb +7 -15
  18. data/lib/bridgetown-core/concerns/validatable.rb +2 -2
  19. data/lib/bridgetown-core/configuration.rb +14 -6
  20. data/lib/bridgetown-core/converter.rb +0 -42
  21. data/lib/bridgetown-core/converters/erb_templates.rb +75 -16
  22. data/lib/bridgetown-core/converters/liquid_templates.rb +96 -0
  23. data/lib/bridgetown-core/converters/markdown.rb +0 -3
  24. data/lib/bridgetown-core/document.rb +34 -21
  25. data/lib/bridgetown-core/drops/site_drop.rb +5 -1
  26. data/lib/bridgetown-core/drops/unified_payload_drop.rb +0 -1
  27. data/lib/bridgetown-core/drops/url_drop.rb +19 -3
  28. data/lib/bridgetown-core/excerpt.rb +1 -1
  29. data/lib/bridgetown-core/filters.rb +37 -55
  30. data/lib/bridgetown-core/filters/condition_helpers.rb +56 -0
  31. data/lib/bridgetown-core/frontmatter_defaults.rb +17 -0
  32. data/lib/bridgetown-core/generators/prototype_generator.rb +42 -25
  33. data/lib/bridgetown-core/helpers.rb +84 -0
  34. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  35. data/lib/bridgetown-core/log_writer.rb +2 -2
  36. data/lib/bridgetown-core/page.rb +8 -2
  37. data/lib/bridgetown-core/plugin_manager.rb +34 -1
  38. data/lib/bridgetown-core/reader.rb +2 -4
  39. data/lib/bridgetown-core/readers/collection_reader.rb +1 -0
  40. data/lib/bridgetown-core/readers/data_reader.rb +4 -3
  41. data/lib/bridgetown-core/readers/defaults_reader.rb +27 -0
  42. data/lib/bridgetown-core/readers/layout_reader.rb +1 -0
  43. data/lib/bridgetown-core/readers/page_reader.rb +1 -0
  44. data/lib/bridgetown-core/readers/post_reader.rb +29 -15
  45. data/lib/bridgetown-core/readers/static_file_reader.rb +1 -0
  46. data/lib/bridgetown-core/renderer.rb +42 -160
  47. data/lib/bridgetown-core/ruby_template_view.rb +26 -22
  48. data/lib/bridgetown-core/site.rb +14 -2
  49. data/lib/bridgetown-core/tags/find.rb +86 -0
  50. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  51. data/lib/bridgetown-core/tags/t.rb +14 -0
  52. data/lib/bridgetown-core/utils.rb +16 -2
  53. data/lib/bridgetown-core/utils/ruby_exec.rb +1 -1
  54. data/lib/bridgetown-core/version.rb +2 -2
  55. data/lib/bridgetown-core/watcher.rb +1 -0
  56. data/lib/site_template/src/images/.keep +1 -0
  57. metadata +29 -6
@@ -7,6 +7,7 @@ module Bridgetown
7
7
  include Configurable
8
8
  include Content
9
9
  include Extensible
10
+ include Localizable
10
11
  include Processable
11
12
  include Renderable
12
13
  include Writable
@@ -14,8 +15,18 @@ module Bridgetown
14
15
  attr_reader :root_dir, :source, :dest, :cache_dir, :config,
15
16
  :regenerator, :liquid_renderer, :components_load_paths,
16
17
  :includes_load_paths
17
- attr_accessor :layouts, :pages, :static_files,
18
- :exclude, :include, :lsi, :highlighter, :permalink_style,
18
+
19
+ # All files not pages/documents or structured data in the source folder
20
+ # @return [Array<StaticFile>]
21
+ attr_accessor :static_files
22
+
23
+ # @return [Array<Layout>]
24
+ attr_accessor :layouts
25
+
26
+ # @return [Array<Page>]
27
+ attr_accessor :pages
28
+
29
+ attr_accessor :exclude, :include, :lsi, :highlighter, :permalink_style,
19
30
  :time, :future, :unpublished, :limit_posts,
20
31
  :keep_files, :baseurl, :data, :file_read_opts,
21
32
  :plugin_manager, :converters, :generators, :reader
@@ -25,6 +36,7 @@ module Bridgetown
25
36
  # config - A Hash containing site configuration details.
26
37
  def initialize(config)
27
38
  self.config = config
39
+ locale
28
40
 
29
41
  @plugin_manager = PluginManager.new(self)
30
42
  @cleaner = Cleaner.new(self)
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class Find < Liquid::Tag
6
+ include Bridgetown::Filters::ConditionHelpers
7
+ include Bridgetown::LiquidExtensions
8
+
9
+ SYNTAX = %r!^(.*?) (where|in) (.*?),(.*)$!.freeze
10
+ CONDITIONS_SEP = "~FINDSEP~"
11
+
12
+ def initialize(tag_name, markup, tokens)
13
+ super
14
+ if markup.strip =~ SYNTAX
15
+ @new_var_name = Regexp.last_match(1).strip
16
+ @single_or_group = Regexp.last_match(2)
17
+ @arr_name = Regexp.last_match(3).strip
18
+ @conditions = process_conditions(Regexp.last_match(4).strip)
19
+ else
20
+ raise SyntaxError, <<~MSG
21
+ Syntax Error in tag 'find' while parsing the following markup:
22
+
23
+ #{markup}
24
+
25
+ Valid syntax: find <varname> where|in <array>, <condition(s)>
26
+ MSG
27
+ end
28
+ end
29
+
30
+ def render(context)
31
+ @group = lookup_variable(context, @arr_name)
32
+ return "" unless @group.respond_to?(:select)
33
+
34
+ @group = @group.values if @group.is_a?(Hash)
35
+
36
+ expression = @conditions.split(CONDITIONS_SEP).map do |condition|
37
+ "__find_tag_item__.#{condition.strip}"
38
+ end.join(" and ")
39
+ @liquid_condition = parse_condition(expression)
40
+
41
+ context[@new_var_name] = if @single_or_group == "where"
42
+ group_evaluate(context)
43
+ else
44
+ single_evaluate(context)
45
+ end
46
+
47
+ ""
48
+ end
49
+
50
+ private
51
+
52
+ def process_conditions(conditions)
53
+ processed_conditions = +""
54
+ in_quotes = false
55
+
56
+ conditions.each_char do |c|
57
+ in_quotes = !in_quotes if c == '"'
58
+
59
+ processed_conditions << (c == "," && !in_quotes ? CONDITIONS_SEP : c)
60
+ end
61
+
62
+ processed_conditions
63
+ end
64
+
65
+ def group_evaluate(context)
66
+ context.stack do
67
+ @group.select do |object|
68
+ context["__find_tag_item__"] = object
69
+ @liquid_condition.evaluate(context)
70
+ end
71
+ end || []
72
+ end
73
+
74
+ def single_evaluate(context)
75
+ context.stack do
76
+ @group.find do |object|
77
+ context["__find_tag_item__"] = object
78
+ @liquid_condition.evaluate(context)
79
+ end
80
+ end || nil
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ Liquid::Template.register_tag("find", Bridgetown::Tags::Find)
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  module Tags
5
5
  class BlockRenderTag < Liquid::Block
6
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
6
+ # rubocop:disable Metrics/MethodLength
7
7
  def render(context)
8
8
  context.stack({}) do
9
9
  # unindent the incoming text
@@ -37,7 +37,7 @@ module Bridgetown
37
37
  .render_tag(context, +"")
38
38
  end
39
39
  end
40
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
40
+ # rubocop:enable Metrics/MethodLength
41
41
 
42
42
  private
43
43
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Tags
5
+ class TranslationTag < Liquid::Tag
6
+ def render(_context)
7
+ key = @markup.strip
8
+ I18n.t(key)
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ Liquid::Template.register_tag("t", Bridgetown::Tags::TranslationTag)
@@ -14,8 +14,8 @@ module Bridgetown
14
14
  # Constants for use in #slugify
15
15
  SLUGIFY_MODES = %w(raw default pretty simple ascii latin).freeze
16
16
  SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
17
- SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^[:alnum:]]+").freeze
18
- SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze
17
+ SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}]+").freeze
18
+ SLUGIFY_PRETTY_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}._~!$&'()+,;=@]+").freeze
19
19
  SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
20
20
 
21
21
  # Takes a slug and turns it into a simple title.
@@ -23,6 +23,20 @@ module Bridgetown
23
23
  slug.gsub(%r![_ ]!, "-").split("-").map!(&:capitalize).join(" ")
24
24
  end
25
25
 
26
+ # XML escape a string for use. Replaces any special characters with
27
+ # appropriate HTML entity replacements.
28
+ #
29
+ # Examples
30
+ #
31
+ # xml_escape('foo "bar" <baz>')
32
+ # # => "foo &quot;bar&quot; &lt;baz&gt;"
33
+ #
34
+ # @param input [String] The String to escape.
35
+ # @return [String] the escaped String.
36
+ def xml_escape(input)
37
+ input.to_s.encode(xml: :attr).gsub(%r!\A"|"\Z!, "")
38
+ end
39
+
26
40
  # Non-destructive version of deep_merge_hashes! See that method.
27
41
  #
28
42
  # Returns the merged hashes.
@@ -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.with_indifferent_access : output
62
+ output.is_a?(Hash) ? output.with_dot_access : output
63
63
  end
64
64
  end
65
65
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.16.0.beta2"
5
- CODE_NAME = "Crystal Springs"
4
+ VERSION = "0.18.1"
5
+ CODE_NAME = "Taylor Street"
6
6
  end
@@ -130,6 +130,7 @@ module Bridgetown
130
130
  Bridgetown::Hooks.trigger :site, :pre_reload, site
131
131
  Bridgetown::Hooks.clear_reloadable_hooks
132
132
  site.plugin_manager.reload_plugin_files
133
+ site.plugin_manager.reload_component_loaders
133
134
  site.process
134
135
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
135
136
  " #{(Time.now - time).ceil(2)} seconds."
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.beta2
4
+ version: 0.18.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-07-24 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: awesome_print
42
+ name: amazing_print
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.8'
47
+ version: '1.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.8'
54
+ version: '1.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: colorator
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -298,6 +312,7 @@ executables:
298
312
  extensions: []
299
313
  extra_rdoc_files: []
300
314
  files:
315
+ - ".yardopts"
301
316
  - Rakefile
302
317
  - bin/bridgetown
303
318
  - bridgetown-core.gemspec
@@ -327,6 +342,7 @@ files:
327
342
  - lib/bridgetown-core/concerns/site/configurable.rb
328
343
  - lib/bridgetown-core/concerns/site/content.rb
329
344
  - lib/bridgetown-core/concerns/site/extensible.rb
345
+ - lib/bridgetown-core/concerns/site/localizable.rb
330
346
  - lib/bridgetown-core/concerns/site/processable.rb
331
347
  - lib/bridgetown-core/concerns/site/renderable.rb
332
348
  - lib/bridgetown-core/concerns/site/writable.rb
@@ -335,6 +351,7 @@ files:
335
351
  - lib/bridgetown-core/converter.rb
336
352
  - lib/bridgetown-core/converters/erb_templates.rb
337
353
  - lib/bridgetown-core/converters/identity.rb
354
+ - lib/bridgetown-core/converters/liquid_templates.rb
338
355
  - lib/bridgetown-core/converters/markdown.rb
339
356
  - lib/bridgetown-core/converters/markdown/kramdown_parser.rb
340
357
  - lib/bridgetown-core/converters/smartypants.rb
@@ -355,12 +372,14 @@ files:
355
372
  - lib/bridgetown-core/excerpt.rb
356
373
  - lib/bridgetown-core/external.rb
357
374
  - lib/bridgetown-core/filters.rb
375
+ - lib/bridgetown-core/filters/condition_helpers.rb
358
376
  - lib/bridgetown-core/filters/date_filters.rb
359
377
  - lib/bridgetown-core/filters/grouping_filters.rb
360
378
  - lib/bridgetown-core/filters/url_filters.rb
361
379
  - lib/bridgetown-core/frontmatter_defaults.rb
362
380
  - lib/bridgetown-core/generator.rb
363
381
  - lib/bridgetown-core/generators/prototype_generator.rb
382
+ - lib/bridgetown-core/helpers.rb
364
383
  - lib/bridgetown-core/hooks.rb
365
384
  - lib/bridgetown-core/layout.rb
366
385
  - lib/bridgetown-core/liquid_extensions.rb
@@ -380,6 +399,7 @@ files:
380
399
  - lib/bridgetown-core/reader.rb
381
400
  - lib/bridgetown-core/readers/collection_reader.rb
382
401
  - lib/bridgetown-core/readers/data_reader.rb
402
+ - lib/bridgetown-core/readers/defaults_reader.rb
383
403
  - lib/bridgetown-core/readers/layout_reader.rb
384
404
  - lib/bridgetown-core/readers/page_reader.rb
385
405
  - lib/bridgetown-core/readers/plugin_content_reader.rb
@@ -392,11 +412,13 @@ files:
392
412
  - lib/bridgetown-core/site.rb
393
413
  - lib/bridgetown-core/static_file.rb
394
414
  - lib/bridgetown-core/tags/class_map.rb
415
+ - lib/bridgetown-core/tags/find.rb
395
416
  - lib/bridgetown-core/tags/highlight.rb
396
417
  - lib/bridgetown-core/tags/include.rb
397
418
  - lib/bridgetown-core/tags/link.rb
398
419
  - lib/bridgetown-core/tags/post_url.rb
399
420
  - lib/bridgetown-core/tags/render_content.rb
421
+ - lib/bridgetown-core/tags/t.rb
400
422
  - lib/bridgetown-core/tags/webpack_path.rb
401
423
  - lib/bridgetown-core/tags/with.rb
402
424
  - lib/bridgetown-core/url.rb
@@ -430,6 +452,7 @@ files:
430
452
  - lib/site_template/src/_posts/0000-00-00-welcome-to-bridgetown.md.erb
431
453
  - lib/site_template/src/about.md
432
454
  - lib/site_template/src/favicon.ico
455
+ - lib/site_template/src/images/.keep
433
456
  - lib/site_template/src/index.md
434
457
  - lib/site_template/src/posts.md
435
458
  - lib/site_template/start.js
@@ -459,7 +482,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
459
482
  - !ruby/object:Gem::Version
460
483
  version: 2.7.0
461
484
  requirements: []
462
- rubygems_version: 3.0.6
485
+ rubygems_version: 3.1.4
463
486
  signing_key:
464
487
  specification_version: 4
465
488
  summary: A Webpack-aware, Ruby-based static site generator for the modern Jamstack