togglate 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8838d984a567e19332eefd8db08ac37d50087ba9
4
- data.tar.gz: 918a7a0d84ca37b6e509b03ee9f02b2e431d48f0
3
+ metadata.gz: 65547c6e81808aac70c1c4d2e5090f9d8f5922b6
4
+ data.tar.gz: ab0e68cce467df0c9ddb5cb80bbe68bd186b9832
5
5
  SHA512:
6
- metadata.gz: 963997000ded8bfa81f8246e6ba3dd6f09dfedf0fc207921919095001896bfc7e84d191f0dd5fdef4eb0a65d73a100fe22d36688f7a6521813bcdb0c5ddf9cec
7
- data.tar.gz: 42948d55aa29bd9802fca99a13ba90335771c333bb1d9811f4dd410b222470e706ea20e17f8583477df6e4d883fabf6bce2f011510637c8f399d8221cbeab94a
6
+ metadata.gz: 196facfe16d6a389e7768f621fc32a604d92395daf3c9549364a7d4d374134e2f8483a12ddf923e0388dcb8bfb15e2d08201511054beb9e11eda922d009d4134
7
+ data.tar.gz: 18fac88443c51e12acc9e85eee4c9d2631df1788bc7047bcdf4f7b6801322be669af499664718f3f45964e691b3e8c4345427f39f39079cb1fce24ea63bacf80
@@ -9,11 +9,17 @@ class Togglate::BlockWrapper
9
9
  @text = text
10
10
  @wrapper = wrapper
11
11
  @pretext = pretext
12
- @wrap_exceptions = wrap_exceptions
13
12
  @translate = set_translate_opt(opts[:translate])
14
13
  @timeout = opts.fetch(:timeout, 5)
15
14
  @email = opts[:email]
15
+ @blank_line_re = /^\s*$/
16
16
  @indent_re = /^\s{4,}\S/
17
+ @block_tags = {
18
+ fenced: /^```/,
19
+ liquid: /^{%/,
20
+ html: /^<(?!img|br|hr|!--).+>\s*$/
21
+ }
22
+ @wrap_exceptions = wrap_exceptions.map { |key| @block_tags[key] }
17
23
  end
18
24
 
19
25
  def run
@@ -33,7 +39,7 @@ class Togglate::BlockWrapper
33
39
  if blank_line?(line)
34
40
  true
35
41
  else
36
- :alone # line just after 4 indent block marked :alone
42
+ :_alone # line just after 4 indent block marked :_alone
37
43
  end
38
44
  else
39
45
  blank_line?(line) && !in_block && !in_indent
@@ -41,8 +47,8 @@ class Togglate::BlockWrapper
41
47
  end
42
48
  end
43
49
 
44
- def blank_line?(line, blank_line_re:/^\s*$/)
45
- !line.match(blank_line_re).nil?
50
+ def blank_line?(line)
51
+ !line.match(@blank_line_re).nil?
46
52
  end
47
53
 
48
54
  def true_to_false?(prev, curr)
@@ -50,8 +56,8 @@ class Togglate::BlockWrapper
50
56
  [prev, curr] == [true, false]
51
57
  end
52
58
 
53
- def in_block?(line, in_block, block_tags:[/^```/, /^{%/])
54
- return !in_block if block_tags.any? { |ex| line.match ex }
59
+ def in_block?(line, in_block)
60
+ return !in_block if @block_tags.any? { |_, ex| line.match ex }
55
61
  in_block
56
62
  end
57
63
 
@@ -66,12 +72,12 @@ class Togglate::BlockWrapper
66
72
  end
67
73
 
68
74
  def wrap_chunks(chunks)
69
- # a line just after 4 indent block(marked :alone) is
75
+ # a line just after 4 indent block(marked :_alone) is
70
76
  # saved to local var 'reserve', then it is merged with
71
77
  # next lines or wrapped solely depend the type of next lines
72
78
  reserve = nil
73
79
  wrap_lines = chunks.inject([]) do |m, (is_blank_line, lines)|
74
- next m.tap { reserve = lines } if is_blank_line == :alone
80
+ next m.tap { reserve = lines } if is_blank_line == :_alone
75
81
 
76
82
  if is_blank_line || exception_block?(lines.first)
77
83
  if reserve
data/lib/togglate/cli.rb CHANGED
@@ -12,7 +12,7 @@ module Togglate
12
12
  def create(file)
13
13
  text = File.read(file)
14
14
  opts = symbolize_keys(options)
15
- blocks = [/^```/, /^{%/]
15
+ blocks = %i(fenced liquid html)
16
16
  opts.update(wrap_exceptions:blocks) if opts[:code_block]
17
17
  opts.update(translate:nil) if opts[:translate].empty?
18
18
  puts Togglate.create(text, opts)
@@ -1,3 +1,3 @@
1
1
  module Togglate
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -35,3 +35,17 @@ def hello
35
35
  end
36
36
  ```
37
37
  -->
38
+
39
+ <!--original
40
+ <table>
41
+ <tr><th>Header</th></tr>
42
+
43
+ <tr><td>Data</td></tr>
44
+ </table>
45
+ -->
46
+
47
+ <table>
48
+ <tr><th>Header</th></tr>
49
+
50
+ <tr><td>Data</td></tr>
51
+ </table>
@@ -11,3 +11,9 @@ def hello
11
11
  puts :hello
12
12
  end
13
13
  ```
14
+
15
+ <table>
16
+ <tr><th>Header</th></tr>
17
+
18
+ <tr><td>Data</td></tr>
19
+ </table>
@@ -90,7 +90,57 @@ EOS
90
90
  "\n",
91
91
  " end tell\n",
92
92
  "\n"]],
93
- [:alone, [" line\n"]]]
93
+ [:_alone, [" line\n"]]]
94
+ expect(wrapper.send(:build_chunks).to_a).to eq exp
95
+ end
96
+ end
97
+
98
+ context "with html tag blocks" do
99
+ it "wraps them as target blocks" do
100
+ text =<<-EOS
101
+ #title
102
+
103
+ <table>
104
+ <tr><th>Header</th></tr>
105
+
106
+ <tr><td>Data</td></tr>
107
+ </table>
108
+ EOS
109
+
110
+ wrapper = Togglate::BlockWrapper.new(text)
111
+ exp = [[false, ["#title\n"]],
112
+ [true, ["\n"]],
113
+ [false, ["<table>\n",
114
+ " <tr><th>Header</th></tr>\n",
115
+ "\n",
116
+ " <tr><td>Data</td></tr>\n",
117
+ "</table>\n"]]]
118
+ expect(wrapper.send(:build_chunks).to_a).to eq exp
119
+ end
120
+
121
+ it "wraps self-closing tags as target blocks" do
122
+ text =<<-EOS
123
+ #title
124
+
125
+ <!-- comment -->
126
+
127
+ <br />
128
+
129
+ <img src="img.png" />
130
+
131
+ <hr />
132
+ EOS
133
+
134
+ wrapper = Togglate::BlockWrapper.new(text)
135
+ exp = [[false, ["#title\n"]],
136
+ [true, ["\n"]],
137
+ [false, ["<!-- comment -->\n"]],
138
+ [true, ["\n"]],
139
+ [false, ["<br />\n"]],
140
+ [true, ["\n"]],
141
+ [false, ["<img src=\"img.png\" />\n"]],
142
+ [true, ["\n"]],
143
+ [false, ["<hr />\n"]]]
94
144
  expect(wrapper.send(:build_chunks).to_a).to eq exp
95
145
  end
96
146
  end
@@ -32,8 +32,13 @@ describe Togglate::CLI do
32
32
  context "set code-block option to true" do
33
33
  it "not wraps fenced and indented code blocks" do
34
34
  Togglate::CLI.start(['create', 'README.md', '--code-block'])
35
- expect($stdout.string).to match(/^\n {4}% ruby title\.rb\n$/)
36
- expect($stdout.string).to match(/^\n```ruby.*```\n$/m)
35
+ expect($stdout.string).to match(/\n\n {4}% ruby.*\n\n/m)
36
+ expect($stdout.string).to match(/\n\n```ruby.*```\n\n/m)
37
+ end
38
+
39
+ it "not wraps html tags" do
40
+ Togglate::CLI.start(['create', 'README.md', '--code-block'])
41
+ expect($stdout.string).to match(/\n\n<table>.*<\/table>\n\n/m)
37
42
  end
38
43
  end
39
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: togglate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-07 00:00:00.000000000 Z
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor