tbpgr_utils 0.0.114 → 0.0.115

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -96,6 +96,7 @@ Or install it yourself as:
96
96
  |[MarkdownString.backquotes](#markdownstringbackquotes) |Return markdown backquotes |
97
97
  |[MarkdownString.bold](#markdownstringbold) |Return markdown bold |
98
98
  |[MarkdownString.code](#markdownstringcode) |Return markdown code |
99
+ |[MarkdownString.codes](#markdownstringcodes) |Return markdown codes |
99
100
  |[MarkdownString.heading1](#markdownstringheading1) |Return markdown heading level1 from text |
100
101
  |[MarkdownString.heading2](#markdownstringheading2) |Return markdown heading level2 from text |
101
102
  |[MarkdownString.heading3](#markdownstringheading3) |Return markdown heading level3 from text |
@@ -2334,6 +2335,26 @@ MarkdownString.code('print "hoge"') # => '`print "hoge"`'
2334
2335
 
2335
2336
  [back to list](#list)
2336
2337
 
2338
+ ### MarkdownString.codes
2339
+ ~~~ruby
2340
+ require 'markdown_string'
2341
+ MarkdownString.codes("class Hoge\n def hoge\n 'hoge'\n end\nend\n")
2342
+ ~~~
2343
+
2344
+ result
2345
+
2346
+ ~~~
2347
+ ~~~ruby
2348
+ class Hoge
2349
+ def hoge
2350
+ 'hoge'
2351
+ end
2352
+ end
2353
+ ~~~
2354
+ ~~~
2355
+
2356
+ [back to list](#list)
2357
+
2337
2358
  ### MarkdownString.heading1
2338
2359
  ~~~ruby
2339
2360
  require 'markdown_string'
@@ -3493,6 +3514,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3493
3514
  https://github.com/tbpgr/tbpgr_utils_snippets
3494
3515
 
3495
3516
  ## History
3517
+ * version 0.0.115 : add MarkdownString#codes
3496
3518
  * version 0.0.114 : add MarkdownString#code
3497
3519
  * version 0.0.113 : add MarkdownString#link
3498
3520
  * version 0.0.112 : add MarkdownString#backquotes
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ class MarkdownString
4
+ # Return markdown codes from text
5
+ #
6
+ # === Example
7
+ #
8
+ # MarkdownString.codes("class Hoge\n def hoge\n 'hoge'\n end\nend\n")
9
+ #
10
+ # result
11
+ #
12
+ # ~~~ruby
13
+ # class Hoge
14
+ # def hoge
15
+ # 'hoge'
16
+ # end
17
+ # end
18
+ # ~~~
19
+ #
20
+ def self.codes(text, lang = nil)
21
+ lang = '' if lang.nil?
22
+ text = '' if text.nil?
23
+ return text unless text.is_a?(String)
24
+ "~~~#{lang}\n#{text}\n~~~\n"
25
+ end
26
+ end
@@ -3,6 +3,7 @@
3
3
  require 'markdown/backquotes'
4
4
  require 'markdown/bold'
5
5
  require 'markdown/code'
6
+ require 'markdown/codes'
6
7
  require 'markdown/heading'
7
8
  require 'markdown/hr'
8
9
  require 'markdown/italic'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.114'
5
+ VERSION = '0.0.115'
6
6
  end
@@ -0,0 +1,96 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'markdown/codes'
4
+
5
+ describe MarkdownString do
6
+ context :codes do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'string case',
11
+ input: "class Hoge\n def hoge\n 'hoge'\n end\nend",
12
+ lang: 'ruby',
13
+ expected: <<-EOS
14
+ ~~~ruby
15
+ class Hoge
16
+ def hoge
17
+ 'hoge'
18
+ end
19
+ end
20
+ ~~~
21
+ EOS
22
+ },
23
+ {
24
+ case_no: 2,
25
+ case_title: 'string no lang case',
26
+ input: "class Hoge\n def hoge\n 'hoge'\n end\nend",
27
+ lang: nil,
28
+ expected: <<-EOS
29
+ ~~~
30
+ class Hoge
31
+ def hoge
32
+ 'hoge'
33
+ end
34
+ end
35
+ ~~~
36
+ EOS
37
+ },
38
+ {
39
+ case_no: 3,
40
+ case_title: 'not string case',
41
+ input: 1,
42
+ lang: 'ruby',
43
+ expected: 1,
44
+ },
45
+ {
46
+ case_no: 4,
47
+ case_title: 'empty case',
48
+ input: '',
49
+ lang: 'ruby',
50
+ expected: <<-EOS
51
+ ~~~ruby
52
+
53
+ ~~~
54
+ EOS
55
+ },
56
+ {
57
+ case_no: 5,
58
+ case_title: 'nil case',
59
+ input: nil,
60
+ lang: 'ruby',
61
+ expected: <<-EOS
62
+ ~~~ruby
63
+
64
+ ~~~
65
+ EOS
66
+ },
67
+ ]
68
+
69
+ cases.each do |c|
70
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
71
+ begin
72
+ case_before c
73
+
74
+ # -- given --
75
+ # nothing
76
+
77
+ # -- when --
78
+ actual = MarkdownString.codes c[:input], c[:lang]
79
+
80
+ # -- then --
81
+ expect(actual).to eq(c[:expected])
82
+ ensure
83
+ case_after c
84
+ end
85
+ end
86
+
87
+ def case_before(c)
88
+ # implement each case before
89
+ end
90
+
91
+ def case_after(c)
92
+ # implement each case after
93
+ end
94
+ end
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.114
4
+ version: 0.0.115
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-01 00:00:00.000000000 Z
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &15775032 !ruby/object:Gem::Requirement
16
+ requirement: &27318012 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15775032
24
+ version_requirements: *27318012
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &15771696 !ruby/object:Gem::Requirement
27
+ requirement: &27316524 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *15771696
35
+ version_requirements: *27316524
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &15786060 !ruby/object:Gem::Requirement
38
+ requirement: &27315576 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15786060
46
+ version_requirements: *27315576
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &15780984 !ruby/object:Gem::Requirement
49
+ requirement: &27314844 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *15780984
57
+ version_requirements: *27314844
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &15794292 !ruby/object:Gem::Requirement
60
+ requirement: &27313560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *15794292
68
+ version_requirements: *27313560
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -111,6 +111,7 @@ files:
111
111
  - lib/markdown/backquotes.rb
112
112
  - lib/markdown/bold.rb
113
113
  - lib/markdown/code.rb
114
+ - lib/markdown/codes.rb
114
115
  - lib/markdown/heading.rb
115
116
  - lib/markdown/hr.rb
116
117
  - lib/markdown/italic.rb
@@ -242,6 +243,7 @@ files:
242
243
  - spec/markdown/backquotes_spec.rb
243
244
  - spec/markdown/bold_spec.rb
244
245
  - spec/markdown/code_spec.rb
246
+ - spec/markdown/codes_spec.rb
245
247
  - spec/markdown/heading_spec.rb
246
248
  - spec/markdown/hr_spec.rb
247
249
  - spec/markdown/italic_spec.rb
@@ -388,6 +390,7 @@ test_files:
388
390
  - spec/markdown/backquotes_spec.rb
389
391
  - spec/markdown/bold_spec.rb
390
392
  - spec/markdown/code_spec.rb
393
+ - spec/markdown/codes_spec.rb
391
394
  - spec/markdown/heading_spec.rb
392
395
  - spec/markdown/hr_spec.rb
393
396
  - spec/markdown/italic_spec.rb