code2rubylearning 0.1.6 → 0.1.7

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.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Rudi Luzar
1
+ Copyright (c) 2012-2013 Rudi Luzar
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -30,6 +30,11 @@ begin
30
30
  options[:prg_link] = false
31
31
  end
32
32
 
33
+ options[:linenumbers] = false
34
+ opt.on( '-l', '--linenumbers', 'Add line number option to code header' ) do
35
+ options[:linenumbers] = true
36
+ end
37
+
33
38
  opt.on( '-h', '--help', 'Display help screen' ) do
34
39
  puts opt
35
40
  exit 1
@@ -21,8 +21,12 @@ module Code2rubylearning
21
21
  if options[:prg_link]
22
22
  @buffer << "<a href=\"https://github.com/rudicode/code2rubylearning/wiki\">Posted with code2rubylearning v#{ VERSION }</a>\n"
23
23
  end
24
+
24
25
  Clippy.copy @buffer unless @buffer.empty?
25
26
  puts @buffer if options[:stdout]
27
+
28
+ @buffer
29
+
26
30
  end
27
31
 
28
32
  end
@@ -29,6 +29,5 @@ module Code2rubylearning
29
29
  def identify_file_type
30
30
  @type = "ruby"
31
31
  end
32
-
33
32
  end
34
33
  end
@@ -2,22 +2,35 @@ module Code2rubylearning
2
2
  class Filter
3
3
  def initialize current_file, options
4
4
  @current_file = current_file
5
+ @name = current_file.name
6
+ @data = current_file.data
7
+ @type = current_file.type
5
8
  @options = options
6
9
  end
7
10
 
8
- def apply #input, file_name
9
- # add_header(file_name) << convert(input) << add_footer
10
- add_header(@current_file.name) << convert(@current_file.data) << add_footer
11
+ def apply
12
+ header(@name) << convert(@data) << footer
11
13
  end
12
14
 
13
- def add_header file_name
14
- type = @current_file.type
15
- header = "[code #{ type }]\n"
16
- header << "#filename: #{ file_name }\n" if @options[:filenames]
15
+ def header file_name
16
+ header = "[code #{ @type }#{@options[:linenumbers] ? ' linenumbers' : ''}]\n"
17
+ if @options[:filenames]
18
+
19
+ data_lines = @data.split("\n")
20
+
21
+ if data_lines.first.include? "#!"
22
+ bin_line = data_lines.first + "\n"
23
+ header << bin_line
24
+ @data = @data.gsub(bin_line, "")
25
+ end
26
+
27
+ header << "#filename: #{ file_name }\n"
28
+
29
+ end
17
30
  header
18
31
  end
19
32
 
20
- def add_footer
33
+ def footer
21
34
  "[/code]\n"
22
35
  end
23
36
 
@@ -1,3 +1,3 @@
1
1
  module Code2rubylearning
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ def there
3
+ "There"
4
+ end
@@ -41,15 +41,22 @@ describe "Filter" do
41
41
  @filter = Filter.new(@original_file, @options)
42
42
  end
43
43
 
44
- it "should add [code ruby] to original string" do
44
+ it "should add [code ruby] to header" do
45
45
  expected = "[code ruby]\n"
46
46
  @filter.apply.must_include expected
47
47
  end
48
48
 
49
- it "should add [/code] to original string" do
49
+ it "should add [/code] to footer" do
50
50
  expected = "[/code]\n"
51
51
  @filter.apply.must_include expected
52
52
  end
53
+
54
+ it "should add 'linenumbers to header" do
55
+ @options[:linenumbers] = true
56
+ expected = "[code ruby linenumbers]"
57
+ @filter.apply.must_include expected
58
+ end
59
+
53
60
  end
54
61
 
55
62
  end
@@ -7,22 +7,16 @@ describe Code2rubylearning do
7
7
 
8
8
  it "should convert a single file" do
9
9
  files = ["spec/assets/file-1.rb"]
10
- Code2rubylearning.start files, @options
10
+ from_clipboard = Code2rubylearning.start files, @options
11
11
 
12
- # check if clipboard contents equal converted file
13
- # be careful clippy adds \r to new lines ( see clippy docs )
14
- from_clipboard = Clippy.paste
15
12
  from_clipboard.must_equal "[code ruby]\r\ndef hello\r\n \"Hello\"\r\nend\r\n[/code]\r\n"
16
13
 
17
14
  end
18
15
 
19
16
  it "should convert multiple files" do
20
17
  files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
21
- Code2rubylearning.start files, @options
18
+ from_clipboard = Code2rubylearning.start files, @options
22
19
 
23
- # check if clipboard contents equal converted file
24
- # be careful clippy adds \r to new lines ( see clippy docs )
25
- from_clipboard = Clippy.paste
26
20
  correct_response = "[code ruby]\r\ndef hello\r\n \"Hello\"\r\nend\r\n[/code]\r\n[code ruby]\r\ndef there\r\n \"There\"\r\nend\r\n[/code]\r\n"
27
21
  from_clipboard.must_equal correct_response
28
22
 
@@ -31,14 +25,46 @@ describe Code2rubylearning do
31
25
  it "should add a program link to the end if :prg_link is true" do
32
26
  @options = { :prg_link => true }
33
27
  files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
34
- Code2rubylearning.start files, @options
28
+ from_clipboard = Code2rubylearning.start files, @options
35
29
 
36
- # check if clipboard contents equal converted file
37
- # be careful clippy adds \r to new lines ( see clippy docs )
38
- from_clipboard = Clippy.paste
39
30
  correct_response = "<a href=\"https://github.com/rudicode/code2rubylearning/wiki\">Posted with code2rubylearning v"
40
31
  from_clipboard.must_include correct_response
41
32
 
42
33
  end
43
34
 
35
+ describe "filename option true" do
36
+
37
+ before :each do
38
+ @options = { :filenames => true }
39
+ end
40
+
41
+ it "should add the given path to file as a comment" do
42
+ files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
43
+ from_clipboard = Code2rubylearning.start files, @options
44
+ from_clipboard.must_include "#filename: " + files[0]
45
+ from_clipboard.must_include "#filename: " + files[1]
46
+ end
47
+
48
+ it "should keep the first line of bin files containing #!" do
49
+ files = ["spec/assets/file-3.rb"]
50
+ from_clipboard = Code2rubylearning.start files, @options
51
+ from_clipboard.must_include "#filename: " + files[0]
52
+ second_line = from_clipboard.split("\n")[1]
53
+ second_line.must_include "#!"
54
+ end
55
+ end
56
+
57
+ describe "filename option false" do
58
+
59
+ before :each do
60
+ @options = { :filenames => false }
61
+ end
62
+
63
+ it "should not output the path to filename in the file" do
64
+ files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
65
+ from_clipboard = Code2rubylearning.start files, @options
66
+ from_clipboard.wont_include "#filename: " + files[0]
67
+ from_clipboard.wont_include "#filename: " + files[1]
68
+ end
69
+ end
44
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code2rubylearning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -52,6 +52,7 @@ files:
52
52
  - lib/code2rubylearning/version.rb
53
53
  - spec/assets/file-1.rb
54
54
  - spec/assets/file-2.rb
55
+ - spec/assets/file-3.rb
55
56
  - spec/code2rubylearning/filehandling_spec.rb
56
57
  - spec/code2rubylearning/filter_spec.rb
57
58
  - spec/code2rubylearning/version_spec.rb
@@ -69,18 +70,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
70
  - - ! '>='
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
- segments:
73
- - 0
74
- hash: -332398925
75
73
  required_rubygems_version: !ruby/object:Gem::Requirement
76
74
  none: false
77
75
  requirements:
78
76
  - - ! '>='
79
77
  - !ruby/object:Gem::Version
80
78
  version: '0'
81
- segments:
82
- - 0
83
- hash: -332398925
84
79
  requirements: []
85
80
  rubyforge_project:
86
81
  rubygems_version: 1.8.24
@@ -91,6 +86,7 @@ summary: command line tool that formats, given source code files, making them re
91
86
  test_files:
92
87
  - spec/assets/file-1.rb
93
88
  - spec/assets/file-2.rb
89
+ - spec/assets/file-3.rb
94
90
  - spec/code2rubylearning/filehandling_spec.rb
95
91
  - spec/code2rubylearning/filter_spec.rb
96
92
  - spec/code2rubylearning/version_spec.rb