jekyll-antex 0.2.2 → 0.3.0

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
  SHA1:
3
- metadata.gz: a1cc97e98e01d13964af2cbe1a631ea2be276310
4
- data.tar.gz: 5e35ad685f11471225ec8d312c35ee5b90a511d7
3
+ metadata.gz: 433dcdd8d21dc9ecf05abd9356a52105aefe7646
4
+ data.tar.gz: 1f233c071d6ed01728d12971c049bc35cce18e43
5
5
  SHA512:
6
- metadata.gz: 78342e277b2b021777af53d0ed3ed6cf82f4ab3ec3ba956a7693d8a69f1b5f51a5640e1563812ec8ceb2a75a6f51e5a53c6b89014d6074c835ce904d0bda6732
7
- data.tar.gz: 763468d9eb428a6294a0fef1a73b43eb1ae913604e7215cfc51283e1f6052d5b94559bd20b95a13c572957799affffe1412fbf4c4a78f2602cc59935df27503c
6
+ metadata.gz: 96479fe656d0ba72cfa2cd8984c1ca9e0653bce6cbabc99ed891a3aa3bd410becd335fef505c165b68720e49c7266129293855708af560305f9cdf7ef9123c8b
7
+ data.tar.gz: 992dea3ca86bac0da9f0b67213884dfa9ee789b82dd4c5be37392fa878477644a57819b6c8009eda9d6de6500e43f767c26b6e96aae370175de5ab85a224adf8
@@ -1,33 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll/antex/error'
4
+ require 'jekyll/antex/utils'
4
5
 
5
6
  module Jekyll
6
7
  module Antex
7
8
  class Alias
8
9
  class InvalidRegexp < Error; end
9
10
 
10
- attr_reader :priority, :regexp, :multiline, :options
11
+ attr_reader :priority, :regexp, :options
11
12
 
12
- def initialize(priority:, options: {},
13
- regexp:, multiline: false, extended: true)
13
+ def initialize(priority:, regexp:, options: {},
14
+ multiline: false, extended: true)
14
15
  @priority = priority.to_i
15
- @regexp = build_regexp source: regexp,
16
- extended: extended,
17
- multiline: multiline
16
+ @regexp = Utils.build_regexp source: regexp,
17
+ extended: extended,
18
+ multiline: multiline
18
19
  validate_regexp!
19
20
  @options = options.to_h
20
21
  end
21
22
 
22
23
  private
23
24
 
24
- def build_regexp(source:, extended:, multiline:)
25
- options = 0
26
- options |= Regexp::EXTENDED if extended
27
- options |= Regexp::MULTILINE if multiline
28
- Regexp.new source, options
29
- end
30
-
31
25
  def validate_regexp!
32
26
  return if @regexp.names.include? 'code'
33
27
  raise InvalidRegexp, <<~MESSAGE
@@ -73,6 +73,21 @@ commands:
73
73
  - "{{ file.fit }}"
74
74
  targets:
75
75
  - "{{ file.svg }}"
76
+ guards:
77
+ comment:
78
+ priority: 1000
79
+ multiline: true
80
+ regexp: >
81
+ <!---
82
+ .*?
83
+ --->
84
+ verbatim:
85
+ priority: 100
86
+ multiline: true
87
+ regexp: >
88
+ ```
89
+ .*?
90
+ ```
76
91
  aliases:
77
92
  # 'internal' must have the highest priority;
78
93
  # it is the liquid tag all other aliases are rendered to.
@@ -6,6 +6,9 @@ require 'jekyll/utils'
6
6
  require 'jekyll/antex/alias'
7
7
  require 'jekyll/antex/dealiaser'
8
8
 
9
+ require 'jekyll/antex/guard'
10
+ require 'jekyll/antex/guardian'
11
+
9
12
  module Jekyll
10
13
  module Antex
11
14
  class Generator < Jekyll::Generator
@@ -23,15 +26,12 @@ module Jekyll
23
26
  private
24
27
 
25
28
  def dealias_resource_content!(site:, resource:)
26
- dealiaser = build_dealiaser site: site, resource: resource
29
+ options = build_options site: site, resource: resource
30
+ guardian = build_guardian options['guards']
31
+ dealiaser = build_dealiaser options['aliases']
32
+ resource.content = guardian.apply resource.content
27
33
  resource.content = dealiaser.parse resource.content
28
- end
29
-
30
- def build_dealiaser(site:, resource:)
31
- options = build_options(site: site, resource: resource)
32
- dealiaser = Jekyll::Antex::Dealiaser.new
33
- dealiaser.add_aliases build_aliases(options['aliases'])
34
- dealiaser
34
+ resource.content = guardian.remove resource.content
35
35
  end
36
36
 
37
37
  def build_options(site:, resource:)
@@ -40,6 +40,24 @@ module Jekyll
40
40
  resource.data['antex'] || {}
41
41
  end
42
42
 
43
+ def build_guardian(guards_options_hash)
44
+ guardian = Jekyll::Antex::Guardian.new
45
+ guardian.add_guards build_guards(guards_options_hash)
46
+ guardian
47
+ end
48
+
49
+ def build_dealiaser(aliases_options_hash)
50
+ dealiaser = Jekyll::Antex::Dealiaser.new
51
+ dealiaser.add_aliases build_aliases(aliases_options_hash)
52
+ dealiaser
53
+ end
54
+
55
+ def build_guards(options_hash)
56
+ options_hash.values.map do |args|
57
+ Guard.new Jekyll::Utils.symbolize_hash_keys(args)
58
+ end
59
+ end
60
+
43
61
  def build_aliases(options_hash)
44
62
  options_hash.values.map do |args|
45
63
  Alias.new Jekyll::Utils.symbolize_hash_keys(args)
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll/antex/utils'
4
+
5
+ module Jekyll
6
+ module Antex
7
+ class Guard
8
+ attr_reader :priority, :regexp
9
+
10
+ def initialize(priority:, regexp:,
11
+ multiline: false, extended: true)
12
+ @priority = priority.to_i
13
+ @regexp = Utils.build_regexp source: regexp,
14
+ extended: extended,
15
+ multiline: multiline
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Jekyll
6
+ module Antex
7
+ class Guardian
8
+ attr_reader :guards
9
+
10
+ def initialize(tag: 'antex')
11
+ @guards = []
12
+ @stash = {}
13
+ @tag = tag
14
+ end
15
+
16
+ def add_guards(guards)
17
+ @guards.concat(guards).sort_by!(&:priority).reverse!
18
+ end
19
+
20
+ def apply(content)
21
+ @content = content.dup
22
+ @stash = {}
23
+ stash_guards
24
+ @content
25
+ end
26
+
27
+ def remove(content)
28
+ @content = content.dup
29
+ unstash_guards
30
+ @content
31
+ end
32
+
33
+ private
34
+
35
+ def stash_guards
36
+ @guards.each do |guard|
37
+ @content.gsub!(guard.regexp) do
38
+ uuid = SecureRandom.uuid
39
+ @stash.store uuid, Regexp.last_match.to_s
40
+ uuid
41
+ end
42
+ end
43
+ end
44
+
45
+ def unstash_guards
46
+ @stash.each do |uuid, guard_match|
47
+ @content.gsub! uuid, guard_match
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
+
5
+ require 'liquid/drop'
6
+ require 'jekyll/drops/drop'
4
7
  require 'jekyll/utils'
8
+ # NOTE: not sure why/how utils require drops, though
5
9
 
6
10
  module Jekyll
7
11
  module Antex
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module Antex
5
+ module Utils
6
+ def self.build_regexp(source:, extended:, multiline:)
7
+ options = 0
8
+ options |= Regexp::EXTENDED if extended
9
+ options |= Regexp::MULTILINE if multiline
10
+ Regexp.new source, options
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Antex
5
- VERSION = '0.2.2'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
data/lib/jekyll/antex.rb CHANGED
@@ -4,7 +4,10 @@ require 'antex'
4
4
 
5
5
  require 'jekyll/antex/version'
6
6
  require 'jekyll/antex/error'
7
+ require 'jekyll/antex/utils'
7
8
  require 'jekyll/antex/options'
9
+ require 'jekyll/antex/guard'
10
+ require 'jekyll/antex/guardian'
8
11
  require 'jekyll/antex/alias'
9
12
  require 'jekyll/antex/dealiaser'
10
13
  require 'jekyll/antex/generator'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-antex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paolo Brasolin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -152,7 +152,10 @@ files:
152
152
  - lib/jekyll/antex/defaults.yml
153
153
  - lib/jekyll/antex/error.rb
154
154
  - lib/jekyll/antex/generator.rb
155
+ - lib/jekyll/antex/guard.rb
156
+ - lib/jekyll/antex/guardian.rb
155
157
  - lib/jekyll/antex/options.rb
158
+ - lib/jekyll/antex/utils.rb
156
159
  - lib/jekyll/antex/version.rb
157
160
  homepage: https://github.com/paolobrasolin/antex
158
161
  licenses: