distorted-jekyll 0.5.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +661 -0
  3. data/README.md +7 -11
  4. data/lib/distorted-jekyll.rb +75 -0
  5. data/lib/distorted-jekyll/13th-style.css +79 -0
  6. data/lib/distorted-jekyll/13th-style.rb +58 -0
  7. data/lib/distorted-jekyll/_config_default.yml +63 -0
  8. data/lib/distorted-jekyll/blocks.rb +16 -0
  9. data/lib/distorted-jekyll/invoker.rb +234 -0
  10. data/lib/distorted-jekyll/liquid_liquid.rb +255 -0
  11. data/lib/distorted-jekyll/liquid_liquid/anchor.liquid +5 -0
  12. data/lib/distorted-jekyll/liquid_liquid/anchor_inline.liquid +1 -0
  13. data/lib/distorted-jekyll/liquid_liquid/embed.liquid +1 -0
  14. data/lib/distorted-jekyll/liquid_liquid/img.liquid +1 -0
  15. data/lib/distorted-jekyll/liquid_liquid/object.liquid +5 -0
  16. data/lib/distorted-jekyll/liquid_liquid/picture.liquid +15 -0
  17. data/lib/distorted-jekyll/liquid_liquid/picture.rb +48 -0
  18. data/lib/distorted-jekyll/liquid_liquid/picture_source.liquid +1 -0
  19. data/lib/distorted-jekyll/liquid_liquid/root.liquid +5 -0
  20. data/lib/distorted-jekyll/liquid_liquid/video.liquid +5 -0
  21. data/lib/distorted-jekyll/liquid_liquid/video_source.liquid +1 -0
  22. data/lib/distorted-jekyll/md_injection.rb +310 -0
  23. data/lib/distorted-jekyll/media_molecule.rb +20 -0
  24. data/lib/distorted-jekyll/media_molecule/font.rb +21 -0
  25. data/lib/distorted-jekyll/media_molecule/image.rb +15 -0
  26. data/lib/distorted-jekyll/media_molecule/never_let_you_down.rb +28 -0
  27. data/lib/distorted-jekyll/media_molecule/pdf.rb +108 -0
  28. data/lib/distorted-jekyll/media_molecule/svg.rb +20 -0
  29. data/lib/distorted-jekyll/media_molecule/text.rb +23 -0
  30. data/lib/distorted-jekyll/media_molecule/video.rb +45 -0
  31. data/lib/distorted-jekyll/monkey_business/jekyll/cleaner.rb +121 -0
  32. data/lib/distorted-jekyll/static_state.rb +160 -0
  33. data/lib/distorted-jekyll/the_setting_sun.rb +179 -0
  34. metadata +37 -34
@@ -0,0 +1,179 @@
1
+ require 'yaml'
2
+ require 'jekyll'
3
+ require 'set'
4
+
5
+ require 'distorted/monkey_business/hash'
6
+ require 'distorted/checking_you_out'
7
+
8
+
9
+ module Jekyll; end
10
+ module Jekyll::DistorteD
11
+
12
+ # Top-level config key (once stringified) for Jekyll and Default YAML.
13
+ CONFIG_ROOT_KEY = :distorted
14
+
15
+ # Filename for default config YAML. Should be a sibling of this file.
16
+ # Don't move this file or the YAML defaults without changing this.
17
+ DEFAULT_CONFIG_FILE_NAME = '_config_default.yml'.freeze
18
+ DEFAULT_CONFIG_PATH = File.join(File.dirname(__FILE__), DEFAULT_CONFIG_FILE_NAME).freeze
19
+
20
+ # Separator character for pretty-printing config hierarchy.
21
+ PP_SEPARATOR = "\u2B9E ".encode('utf-8').freeze
22
+
23
+ # Path separator is almost always '/' internally, but support
24
+ # ALT_SEPARATOR platforms too.
25
+ # On Lunix - Ruby 2.7:
26
+ # irb(main):003:0> File::ALT_SEPARATOR
27
+ # => nil
28
+ # irb(main):004:0> File::SEPARATOR
29
+ # => "/"
30
+ PATH_SEPARATOR = (File::ALT_SEPARATOR || File::SEPARATOR).freeze
31
+
32
+ # Any any attr value will get a to_sym if shorter than this
33
+ # totally arbitrary length, or if the attr key is in the plugged
34
+ # Molecule's set of attrs that take only a defined set of values.
35
+ # My chosen boundary length fits all of the outer-limit tag names I use,
36
+ # like 'medium'. It fits the longest value of Vips::Interesting too,
37
+ # though `crop` will be symbolized based on the other condition.
38
+ ARBITRARY_ATTR_SYMBOL_STRING_LENGTH_BOUNDARY = 13
39
+
40
+
41
+ # Memoization Hash for all settings data so we don't have to reprocess it for additional lookups.
42
+ def self.memories
43
+ @@memories ||= Hash.new
44
+ end
45
+
46
+ # Memoize the complete default-config to avoid touching the filesystem more than once.
47
+ def self.distorted_default_settings
48
+ @@distorted_default_settings ||= YAML.load(File.read(DEFAULT_CONFIG_PATH))
49
+ end
50
+
51
+ # Stores a given settings path/value to our memoization Hash
52
+ # after normalizing the values, so we can be less strict about
53
+ # the YAML formats we accept because YAML is easy to mess up.
54
+ def self.memories!(key_paths, sources)
55
+ # Avoid redundant memory transformations for keys we already have.
56
+ # NOTE: This assumes settings will never change over the execution lifetime
57
+ # of any single DistorteD instance.
58
+ return self.memories.dig(key_paths) if self.memories.has_key?(key_paths)
59
+ # Shorten long path members (any with underscores) so long log lines
60
+ # don't get misaligned easily.
61
+ # Don't log glob paths — those containing as asterisk (*).
62
+ log_key = key_paths.detect { |path| path.none?(:"*") }.map(&:to_s).map{ |component|
63
+ component.include?('_'.freeze) ? component.split('_'.freeze).map(&:chr).join('_'.freeze) : component
64
+ }.join(PP_SEPARATOR.to_s).freeze
65
+
66
+ # Try one one source Proc at a time, looking for every settings-path within it.
67
+ # If *any* config data is returned from a source we stop processing additional sources.
68
+ # This is to allow for default-config overriding because otherwise if we always
69
+ # use the default config it would be impossible to turn off any of that data.
70
+ memory = sources.reduce(nil) { |out, source|
71
+ key_paths.each { |key_path|
72
+ case new = source.call(key_path)
73
+ when [out, new].all? { |c| c&.respond_to?(:update) } then out.update(new)
74
+ when [out, new].all? { |c| c&.respond_to?(:merge) } then out.merge(new)
75
+ when [out, new].all? { |c| c&.respond_to?(:concat) } then out.concat(new)
76
+ else out = new
77
+ end
78
+ }
79
+ Jekyll.logger.debug(log_key, out) unless out.nil?
80
+ break out unless out.nil?
81
+ }
82
+
83
+ # Most of our settings data comes from a YAML source,
84
+ # either Jekyll's config or our Gem's built-in defaults,
85
+ # so we should do some normalization before memoizing.
86
+ memory = case memory
87
+ when Array
88
+ # Transform Array members, then transform the Array itself to a Set to dedupe.
89
+ memory.map{ |array_member|
90
+ case array_member
91
+ # Symbolize Hash keys as well as String values if it has any.
92
+ when Hash then array_member.transform_keys!(&:to_sym).transform_values!{ |hash_value|
93
+ case hash_value
94
+ when String then (hash_value.length <= ARBITRARY_ATTR_SYMBOL_STRING_LENGTH_BOUNDARY) ? hash_value.to_sym : hash_value
95
+ else hash_value
96
+ end
97
+ }
98
+ # For sub-Arrays of our Array, Symbolize their keys
99
+ when Array then array_member.map(&:to_sym)
100
+ # Otherwise just pass it as it was loaded from YAML
101
+ else array_member
102
+ end
103
+ }.to_set
104
+ when Hash
105
+ # Ruby::YAML::load will parse YAML Sets (the `?` list-like syntax)
106
+ # as a Ruby Hash with all-nil values (the internal implementation of Set)
107
+ # unless we give our YAML files some sugar telling it what class we want:
108
+ # https://rhnh.net/2011/01/31/yaml-tutorial/
109
+ #
110
+ # I wouldn't mind maintaining the default-settings YAML file with those tags,
111
+ # but that would make it really tedious and error-prone in the Jekyll config
112
+ # if/when it comes time to override any defaults, so I em ignoring that capability
113
+ # and doing my own normalization here in this method.
114
+ memory.values.all?{|v| v.nil?} ? memory.keys.map(&:to_sym).to_set : memory.transform_keys(&:to_sym)
115
+ else memory
116
+ end
117
+ # Use the `key_paths` Array[Array[String] as the Hash key directly to avoid the complexity
118
+ # of trying to splat it and nest the keys in layers of other Hashes.
119
+ self.memories.store(key_paths, memory)
120
+ end
121
+
122
+ # Generic main config-loading function that will search, in order:
123
+ # - The memoized pre-transformed config data store in-memory.
124
+ # - Jekyll's Site config, for a passed-in site or for the default site.
125
+ # - DistorteD's Gem-internal default config YAML.
126
+ #
127
+ # Optionally provide a class to be used as a fallback for missing keys.
128
+ def self.the_setting_sun(*keys, site: Jekyll.sites.first, **kw)
129
+ return nil if keys.empty?
130
+
131
+ # Normalize given keys into an Array[Array[<whatever>] given these rules:
132
+ #
133
+ # - If all of our given keys are Arrays, assume each Array is a separate settings-path
134
+ # and leave them alone, e.g. [['jekyll', 'destination']] would be passed unchanged.
135
+ #
136
+ # - If some of our given keys are Arrays and some are not, assume the Arrays are incomplete
137
+ # settings-paths (suffixes) and assume the non-Arrays are prefixes that should be applied
138
+ # to each suffix, e.g.
139
+ # ['changes', ['image', '*'], ['image', 'jpeg']] becomes [['changes', 'image', 'jpeg'], ['changes', 'image', '*']]
140
+ #
141
+ # - If none of our given keys are an Array, assume the given keys make up
142
+ # a single settings-path and wrap them in an Array, e.g.:
143
+ # ['jekyll', 'destination'] becomes [['jekyll', 'destination']]
144
+ key_paths = case
145
+ when keys.all?(Array) then keys
146
+ when keys.any?(Array) then
147
+ keys.map.partition(&Array.method(:===)).yield_self.with_object(Array.new) { |(suffixes, prefix), combined_paths|
148
+ suffixes.each{ |suffix| combined_paths.push(suffix.unshift(*prefix)) }
149
+ }
150
+ when keys.none?(Array) then Array[keys]
151
+ end.map { |key_path|
152
+ # Now inspect the first key of each combined path and transform accordingly:
153
+ # - Opposite Day — :jekyll-prefixed paths get the prefix removed
154
+ # because that key level doesn't exist in the Jekyll config.
155
+ # - If it already has out prefix, leave it alone.
156
+ # - Everything else gets our :distorted prefix added if missing
157
+ # so I don't have to refer to the constant externally.
158
+ # Finally, Symbolize errething for Hash key consistency in memoization
159
+ # even though some config getters will map them back to Strings.
160
+ case key_path.first.to_sym
161
+ when :jekyll, :Jekyll then key_path.drop(1)
162
+ when CONFIG_ROOT_KEY then key_path.map(&:to_sym)
163
+ else key_path.unshift(CONFIG_ROOT_KEY).map(&:to_sym)
164
+ end
165
+ }
166
+
167
+ # Do The Thing
168
+ return memories!(key_paths, Array[
169
+ ->(key_path){ site.config.dig(*key_path.map(&:to_s))},
170
+ ->(key_path){ self::distorted_default_settings.dig(*key_path.map(&:to_s))},
171
+ ])
172
+ end # self.the_setting_sun
173
+ end # module Jekyll::DistorteD
174
+
175
+
176
+ module Jekyll::DistorteD::Setting
177
+ # Instance version of Setting entry-point.
178
+ def the_setting_sun(*a, **k, &b); Jekyll::DistorteD::the_setting_sun(*a, **k, &b); end
179
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: distorted-jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - Allison Reid
7
+ - okeeblow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-09 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,28 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.4
89
+ version: 0.7.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.4
97
- - !ruby/object:Gem::Dependency
98
- name: mime-types
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.0'
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.0'
96
+ version: 0.7.0
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: kramdown
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +108,6 @@ dependencies:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
110
  version: '2.0'
125
- - !ruby/object:Gem::Dependency
126
- name: ruby-filemagic
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.7'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.7'
139
111
  description: Jekyll::DistorteD is a Liquid tag for embedding media in a Jekyll site
140
112
  with automatic thumbnailing, cropping, and format conversion.
141
113
  email:
@@ -144,7 +116,38 @@ executables: []
144
116
  extensions: []
145
117
  extra_rdoc_files: []
146
118
  files:
119
+ - LICENSE
147
120
  - README.md
121
+ - lib/distorted-jekyll.rb
122
+ - lib/distorted-jekyll/13th-style.css
123
+ - lib/distorted-jekyll/13th-style.rb
124
+ - lib/distorted-jekyll/_config_default.yml
125
+ - lib/distorted-jekyll/blocks.rb
126
+ - lib/distorted-jekyll/invoker.rb
127
+ - lib/distorted-jekyll/liquid_liquid.rb
128
+ - lib/distorted-jekyll/liquid_liquid/anchor.liquid
129
+ - lib/distorted-jekyll/liquid_liquid/anchor_inline.liquid
130
+ - lib/distorted-jekyll/liquid_liquid/embed.liquid
131
+ - lib/distorted-jekyll/liquid_liquid/img.liquid
132
+ - lib/distorted-jekyll/liquid_liquid/object.liquid
133
+ - lib/distorted-jekyll/liquid_liquid/picture.liquid
134
+ - lib/distorted-jekyll/liquid_liquid/picture.rb
135
+ - lib/distorted-jekyll/liquid_liquid/picture_source.liquid
136
+ - lib/distorted-jekyll/liquid_liquid/root.liquid
137
+ - lib/distorted-jekyll/liquid_liquid/video.liquid
138
+ - lib/distorted-jekyll/liquid_liquid/video_source.liquid
139
+ - lib/distorted-jekyll/md_injection.rb
140
+ - lib/distorted-jekyll/media_molecule.rb
141
+ - lib/distorted-jekyll/media_molecule/font.rb
142
+ - lib/distorted-jekyll/media_molecule/image.rb
143
+ - lib/distorted-jekyll/media_molecule/never_let_you_down.rb
144
+ - lib/distorted-jekyll/media_molecule/pdf.rb
145
+ - lib/distorted-jekyll/media_molecule/svg.rb
146
+ - lib/distorted-jekyll/media_molecule/text.rb
147
+ - lib/distorted-jekyll/media_molecule/video.rb
148
+ - lib/distorted-jekyll/monkey_business/jekyll/cleaner.rb
149
+ - lib/distorted-jekyll/static_state.rb
150
+ - lib/distorted-jekyll/the_setting_sun.rb
148
151
  homepage: https://cooltrainer.org
149
152
  licenses:
150
153
  - AGPL-3.0
@@ -167,5 +170,5 @@ requirements: []
167
170
  rubygems_version: 3.1.4
168
171
  signing_key:
169
172
  specification_version: 4
170
- summary: Media transformation and embedding framework for Jekyll.
173
+ summary: Multimedia toolkit for Jekyll websites.
171
174
  test_files: []