togglate 0.0.3 → 0.0.4

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: a67edbbcb3fc78c147b5d1a686f35091fa974d3a
4
- data.tar.gz: 5ff0bdc8a25fcf43b6662f426fcff2d3ebea10b5
3
+ metadata.gz: d573daf3d95b1c968fffaa6e2f82ef0fd93cefa7
4
+ data.tar.gz: 61addd322ccd6d0596eba3a02cedd430ee14c6b4
5
5
  SHA512:
6
- metadata.gz: 7a5ca7027d328ff4f1e597c2f729f01ffde8129d884328829663dbfb3b72cfd6334b6bd0df08265c984e0e329004b4edc92ef50d73bb0d65827679911d9839bd
7
- data.tar.gz: 3101a22687385fe4b7bf891a125d97c1a37a84de565a476f9a1649ee9b1df2c7ba394b77f955a7c876d61f4b60c0341355275ccd4ab3c77411d40e09731b7a65
6
+ metadata.gz: 9281cc535ab9cdc9e9401a24d29aaa85db22c9286a775d33d085b7b9595696805dd603e4708b6641c32042aac8f68c48bcce46df2b4d828c5f2217a3924f2f66
7
+ data.tar.gz: b1a3aa396ba32ba7b4b50885da5938e6d0141666faaf4d87f40fc5320641935db2334c33e3a8560f2da61e6e4b3bc3f05651a6cfa763c77cd542da7db662a487
data/lib/togglate/cli.rb CHANGED
@@ -8,16 +8,35 @@ module Togglate
8
8
  option :toggle_link_text, type: :array, default:["*", "hide"]
9
9
  option :code_block, aliases:'-c', default:false, type: :boolean, desc:"Enable code blocks not to be wrapped"
10
10
  def create(file)
11
- opts = options.inject({}) { |h, (k,v)| h[k.intern] = v; h } # symbolize keys
11
+ opts = symbolize_keys(options)
12
12
  opts.update(wrap_exceptions:[/^```/, /^ {4}/]) if opts[:code_block]
13
13
  puts Togglate.create(file, opts)
14
14
  end
15
15
 
16
+ desc "append_code FILE", "Append a hover or toggle code to a FILE"
17
+ option :method, aliases:'-m', default:'hover', desc:"Select a display method: 'hover' or 'toggle'"
18
+ option :toggle_link_text, type: :array, default:["*", "hide"]
19
+ def append_code(file)
20
+ text = File.read(file)
21
+ opts = symbolize_keys(options)
22
+ method = opts.delete(:method)
23
+ code = Togglate.append_code(method, opts)
24
+ puts "#{text}\n#{code}"
25
+ rescue => e
26
+ STDERR.puts "something go wrong. #{e}"
27
+ exit
28
+ end
29
+
16
30
  desc "version", "Show Togglate version"
17
31
  def version
18
32
  puts "Togglate #{Togglate::VERSION} (c) 2014 kyoendo"
19
33
  end
20
34
  map "-v" => :version
21
35
 
36
+ no_tasks do
37
+ def symbolize_keys(options)
38
+ options.inject({}) { |h, (k,v)| h[k.intern] = v; h }
39
+ end
40
+ end
22
41
  end
23
42
  end
@@ -1,3 +1,3 @@
1
1
  module Togglate
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -61,4 +61,16 @@ describe Togglate::CLI do
61
61
  end
62
62
  end
63
63
  end
64
+
65
+ describe "#append_code" do
66
+ it "appends hover code to a file" do
67
+ Togglate::CLI.start(['append_code', 'README.md'])
68
+ expect($stdout.string).to match(/<script.*nodeType==8.*<\/script>/m)
69
+ end
70
+
71
+ it "appends toggle code to a file" do
72
+ Togglate::CLI.start(['append_code', 'README.md', '-m=toggle', '--toggle-link-text', 'showme', 'closeme'])
73
+ expect($stdout.string).to match(/<script.*showme.*<\/script>/m)
74
+ end
75
+ end
64
76
  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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-16 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor