togglate 0.1.1 → 0.1.2
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 +4 -4
- data/lib/togglate/cli.rb +17 -1
- data/lib/togglate/version.rb +1 -1
- data/lib/togglate.rb +27 -20
- data/spec/fixtures/README.ja.md +31 -0
- data/spec/fixtures/README.md +0 -1
- data/spec/togglate_cli_spec.rb +16 -0
- data/spec/togglate_spec.rb +15 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3e882d0a7b6b8494adb72255373853b954d24bf
|
4
|
+
data.tar.gz: 2dfa813070babdae9203d5b53075a4eb788ab8dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1034613d6c3c779ea614d79caf82c82c76fdbf34aa944574169d7dce51d68e621567802faeeee62d7f5b0bd6ca7bb640f2a83fbb3a875779d0fead09c82929
|
7
|
+
data.tar.gz: f72edcd08d81e63d99566ecb0e24ae7dfafe00dc6c5bcc24f86db20a4991d6016543422eb15370cd4d47c51595fa41336253848773dd1e198354f128ff07e821
|
data/lib/togglate/cli.rb
CHANGED
@@ -10,10 +10,14 @@ module Togglate
|
|
10
10
|
option :translate, aliases:'-t', type: :hash, default:{}, desc:"Embed machine translated text. ex.-t=to:ja"
|
11
11
|
option :email, desc:"Passing a valid email extends a limit of Mymemory anonymous usage from 100 to 1000 requests/day"
|
12
12
|
def create(file)
|
13
|
+
text = File.read(file)
|
13
14
|
opts = symbolize_keys(options)
|
14
15
|
opts.update(wrap_exceptions:[/^```/, /^ {4}/]) if opts[:code_block]
|
15
16
|
opts.update(translate:nil) if opts[:translate].empty?
|
16
|
-
puts Togglate.create(
|
17
|
+
puts Togglate.create(text, opts)
|
18
|
+
rescue => e
|
19
|
+
STDERR.puts "something go wrong. #{e}"
|
20
|
+
exit
|
17
21
|
end
|
18
22
|
|
19
23
|
desc "append_code FILE", "Append a hover or toggle code to a FILE"
|
@@ -30,6 +34,18 @@ module Togglate
|
|
30
34
|
exit
|
31
35
|
end
|
32
36
|
|
37
|
+
desc "commentout FILE", "Extract commented contents from a FILE"
|
38
|
+
option :remains, aliases:'-r', default:false, type: :boolean, desc:"Output remaining text after extraction of comments"
|
39
|
+
option :tag, aliases:'-t', default:'original', desc:"Specify comment tag name"
|
40
|
+
def commentout(file)
|
41
|
+
text = File.read(file)
|
42
|
+
comments, remains = Togglate.commentout(text, tag:options['tag'])
|
43
|
+
puts options['remains'] ? remains : comments
|
44
|
+
rescue => e
|
45
|
+
STDERR.puts "something go wrong. #{e}"
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
33
49
|
desc "version", "Show Togglate version"
|
34
50
|
def version
|
35
51
|
puts "Togglate #{Togglate::VERSION} (c) 2014 kyoendo"
|
data/lib/togglate/version.rb
CHANGED
data/lib/togglate.rb
CHANGED
@@ -6,26 +6,32 @@ require "togglate/block_wrapper"
|
|
6
6
|
require "togglate/cli"
|
7
7
|
|
8
8
|
module Togglate
|
9
|
-
|
10
|
-
text =
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
class << self
|
10
|
+
def create(text, opts={})
|
11
|
+
wrapped = BlockWrapper.new(text, opts).run
|
12
|
+
if opts[:embed_code]
|
13
|
+
code = append_code(opts[:method], opts)
|
14
|
+
"#{wrapped}\n#{code}"
|
15
|
+
else
|
16
|
+
wrapped
|
17
|
+
end
|
17
18
|
end
|
18
|
-
rescue => e
|
19
|
-
STDERR.puts "something go wrong. #{e}"
|
20
|
-
exit
|
21
|
-
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
def commentout(text, tag:'original')
|
21
|
+
comments = []
|
22
|
+
comment_re = /\n?^<!--#{tag}\n(.*?)^-->\n?/m
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
remains = text.gsub(comment_re) { |m| comments << $1; '' }
|
25
|
+
return comments*"\n", remains
|
26
|
+
end
|
27
|
+
alias :comment_out :commentout
|
28
|
+
|
29
|
+
def append_code(method, opts)
|
30
|
+
send("#{method}_code", opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
def toggle_code(name:'original', toggle_link_text:["*", "hide"], **opts)
|
34
|
+
<<-"CODE"
|
29
35
|
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
30
36
|
<script>
|
31
37
|
$(function() {
|
@@ -51,10 +57,10 @@ $(function() {
|
|
51
57
|
});
|
52
58
|
</script>
|
53
59
|
CODE
|
54
|
-
|
60
|
+
end
|
55
61
|
|
56
|
-
|
57
|
-
|
62
|
+
def hover_code(name:'original', **opts)
|
63
|
+
<<-"CODE"
|
58
64
|
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
59
65
|
<script>
|
60
66
|
$(function() {
|
@@ -67,5 +73,6 @@ $(function() {
|
|
67
73
|
});
|
68
74
|
</script>
|
69
75
|
CODE
|
76
|
+
end
|
70
77
|
end
|
71
78
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# タイトル
|
2
|
+
|
3
|
+
<!--original
|
4
|
+
# Title
|
5
|
+
-->
|
6
|
+
|
7
|
+
プログラミングは楽しい。
|
8
|
+
|
9
|
+
<!--original
|
10
|
+
Programming is fun.
|
11
|
+
-->
|
12
|
+
|
13
|
+
% ruby title.rb
|
14
|
+
|
15
|
+
<!--original
|
16
|
+
% ruby title.rb
|
17
|
+
-->
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
def hello
|
21
|
+
puts :hello
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
<!--original
|
26
|
+
```ruby
|
27
|
+
def hello
|
28
|
+
puts :hello
|
29
|
+
end
|
30
|
+
```
|
31
|
+
-->
|
data/spec/fixtures/README.md
CHANGED
data/spec/togglate_cli_spec.rb
CHANGED
@@ -80,4 +80,20 @@ describe Togglate::CLI do
|
|
80
80
|
expect($stdout.string).to match(/<script.*showme.*<\/script>/m)
|
81
81
|
end
|
82
82
|
end
|
83
|
+
|
84
|
+
describe "#commentout" do
|
85
|
+
it "extract comments from given file" do
|
86
|
+
Togglate::CLI.start(['commentout', 'README.ja.md'])
|
87
|
+
expect($stdout.string).to match(/# Title.*Programming/m)
|
88
|
+
expect($stdout.string).not_to match(/# タイトル.*プログラミングは楽しい/m)
|
89
|
+
end
|
90
|
+
|
91
|
+
context "set remains option to true" do
|
92
|
+
it "outputs remaining text" do
|
93
|
+
Togglate::CLI.start(['commentout', 'README.ja.md', '--remains'])
|
94
|
+
expect($stdout.string).not_to match(/# Title.*Programming/m)
|
95
|
+
expect($stdout.string).to match(/# タイトル.*プログラミングは楽しい/m)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
83
99
|
end
|
data/spec/togglate_spec.rb
CHANGED
@@ -4,6 +4,21 @@ describe Togglate do
|
|
4
4
|
it 'should have a version number' do
|
5
5
|
Togglate::VERSION.should_not be_nil
|
6
6
|
end
|
7
|
+
|
8
|
+
describe ".commentout" do
|
9
|
+
before do
|
10
|
+
@original, @translated = begin
|
11
|
+
%w(README.md README.ja.md).map do |f|
|
12
|
+
File.read File.join(source_root, f)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "extract comments from a text" do
|
18
|
+
comments, remains = Togglate.commentout(@translated)
|
19
|
+
expect(@original == comments).to be_true
|
20
|
+
end
|
21
|
+
end
|
7
22
|
end
|
8
23
|
|
9
24
|
describe Togglate::BlockWrapper do
|
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
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/togglate/cli.rb
|
116
116
|
- lib/togglate/core_ext.rb
|
117
117
|
- lib/togglate/version.rb
|
118
|
+
- spec/fixtures/README.ja.md
|
118
119
|
- spec/fixtures/README.md
|
119
120
|
- spec/fixtures/translated_text.json
|
120
121
|
- spec/spec_helper.rb
|
@@ -146,6 +147,7 @@ signing_key:
|
|
146
147
|
specification_version: 4
|
147
148
|
summary: Create base text for translation, in which original is togglable
|
148
149
|
test_files:
|
150
|
+
- spec/fixtures/README.ja.md
|
149
151
|
- spec/fixtures/README.md
|
150
152
|
- spec/fixtures/translated_text.json
|
151
153
|
- spec/spec_helper.rb
|