code2rubylearning 0.1.3 → 0.1.4

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/Gemfile CHANGED
@@ -41,5 +41,6 @@ group :test do
41
41
  gem 'guard-minitest', '0.5.0'
42
42
  gem 'guard', "~> 1.6.0"
43
43
  gem 'guard-rspec', "~> 2.3.1"
44
+ gem 'simplecov', :require => false, :group => :test
44
45
  end
45
46
 
data/README.md CHANGED
@@ -1,24 +1,22 @@
1
1
  # Code2rubylearning
2
2
  command line tool that formats, given source code files, making them ready for pasting to the rubylearning.org forum.
3
3
 
4
- # Under Development
5
4
  ## Installation
5
+ gem install code2rubylearning
6
+
7
+ Or add this line to your application's Gemfile:
6
8
 
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'code2rubylearning', :git => "https://github.com/rudicode/code2rubylearning.git", :branch => "master"
10
-
11
- And then execute:
9
+ gem "code2rubylearning", "~> 0.1.3"
12
10
 
13
- $ bundle
14
- This should install clippy 1.0.1 as well.
11
+ And then :
12
+ bundle install
13
+
14
+ ## Usage:
15
15
 
16
- To see if it works
16
+ $ code2rubylearning [options] file1 file2 file3 ...
17
17
 
18
- $ bundle exec code2rubylearning
18
+ Check your clipboard, the files should be ready to paste to the forum.
19
19
 
20
- This should copy the text string "Text to copy to clip board." to your clipboard.
21
-
22
20
  ## Contributing
23
21
 
24
22
  1. Fork it
@@ -3,33 +3,42 @@
3
3
  require 'optparse'
4
4
  require 'code2rubylearning'
5
5
 
6
- options = {}
7
-
8
- optparse = OptionParser.new do|opt|
9
- opt.banner = "code2rubylearning version: #{ Code2rubylearning::VERSION }\n\nUsage: code2rubylearning [options] file1 file2 ..."
10
-
11
- # options
12
- options[:stdout] = false
13
- opt.on( '-s', '--stdout', 'Output to stdout' ) do
14
- options[:stdout] = true
15
- end
16
-
17
- options[:combine] = false
18
- opt.on( '-c', '--combine', 'Combine multiple files into one ( not yet implemented )' ) do
19
- options[:combine] = true
6
+ begin
7
+ options = {}
8
+
9
+ optparse = OptionParser.new do|opt|
10
+ opt.banner = "code2rubylearning version: #{ Code2rubylearning::VERSION }\n\nUsage: code2rubylearning [options] file1 file2 ..."
11
+
12
+ # options
13
+ options[:stdout] = false
14
+ opt.on( '-s', '--stdout', 'Output to stdout' ) do
15
+ options[:stdout] = true
16
+ end
17
+
18
+ options[:combine] = false
19
+ opt.on( '-c', '--combine', 'Combine multiple files into one ( not yet implemented )' ) do
20
+ options[:combine] = true
21
+ end
22
+
23
+ options[:filenames] = true
24
+ opt.on( '-f', '--nofilenames', 'Suppress filename line in output' ) do
25
+ options[:filenames] = false
26
+ end
27
+
28
+ opt.on( '-h', '--help', 'Display help screen' ) do
29
+ puts opt
30
+ exit 1
31
+ end
20
32
  end
21
33
 
22
- options[:filenames] = true
23
- opt.on( '-f', '--nofilenames', 'Suppress filename line in output' ) do
24
- options[:filenames] = false
25
- end
34
+ optparse.parse! ARGV
26
35
 
27
- opt.on( '-h', '--help', 'Display help screen' ) do
28
- puts opt
36
+ if ARGV.empty?
37
+ puts optparse
29
38
  exit 1
30
39
  end
31
- end
32
- begin optparse.parse! ARGV
40
+
41
+ Code2rubylearning.start ARGV, options
33
42
 
34
43
  rescue OptionParser::InvalidOption => e
35
44
  puts e
@@ -37,10 +46,3 @@ rescue OptionParser::InvalidOption => e
37
46
  exit 1
38
47
  end
39
48
 
40
- if ARGV.empty?
41
- puts optparse
42
- exit 1
43
- end
44
-
45
- Code2rubylearning.start ARGV, options
46
-
@@ -1,3 +1,3 @@
1
1
  module Code2rubylearning
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -2,16 +2,12 @@ require 'clippy'
2
2
  require 'code2rubylearning/version'
3
3
  require 'code2rubylearning/filter'
4
4
  require 'code2rubylearning/filehandling'
5
- require 'code2rubylearning/parse_cli'
6
5
 
7
6
  module Code2rubylearning
8
7
 
9
8
  extend self
10
9
 
11
- def start args, options
12
- ParseCLI.parse args
13
- files = ParseCLI.files
14
- # options = ParseCLI.options
10
+ def start files, options
15
11
  @buffer = ""
16
12
 
17
13
  files.each do |file|
@@ -0,0 +1,3 @@
1
+ def hello
2
+ "Hello"
3
+ end
@@ -0,0 +1,3 @@
1
+ def there
2
+ "There"
3
+ end
@@ -2,5 +2,30 @@ require "spec_helper"
2
2
 
3
3
  describe Code2rubylearning do
4
4
 
5
+ it "should convert a single file" do
6
+ files = ["spec/assets/file-1.rb"]
7
+ options = { :stdout => false }
8
+ Code2rubylearning.start files, options
9
+
10
+ # check if clipboard contents equal converted file
11
+ # be careful clippy adds \r to new lines ( see clippy docs )
12
+ from_clipboard = Clippy.paste
13
+ from_clipboard.must_equal "[code ruby]\r\ndef hello\r\n \"Hello\"\r\nend\r\n[/code]\r\n"
14
+
15
+ end
16
+
17
+ it "should convert multiple files" do
18
+ files = ["spec/assets/file-1.rb", "spec/assets/file-2.rb"]
19
+ options = { :stdout => false }
20
+ Code2rubylearning.start files, options
21
+
22
+ # check if clipboard contents equal converted file
23
+ # be careful clippy adds \r to new lines ( see clippy docs )
24
+ from_clipboard = Clippy.paste
25
+ 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"
26
+ from_clipboard.must_equal correct_response
27
+
28
+ end
29
+
5
30
 
6
31
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ SimpleCov.command_name 'MiniTest:specs'
1
4
  require "rubygems"
2
5
  require "bundler/setup"
3
6
  require 'minitest/autorun'
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.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -48,11 +48,11 @@ files:
48
48
  - lib/code2rubylearning.rb
49
49
  - lib/code2rubylearning/filehandling.rb
50
50
  - lib/code2rubylearning/filter.rb
51
- - lib/code2rubylearning/parse_cli.rb
52
51
  - lib/code2rubylearning/version.rb
52
+ - spec/assets/file-1.rb
53
+ - spec/assets/file-2.rb
53
54
  - spec/code2rubylearning/filehandling_spec.rb
54
55
  - spec/code2rubylearning/filter_spec.rb
55
- - spec/code2rubylearning/parse_cli_spec.rb
56
56
  - spec/code2rubylearning/version_spec.rb
57
57
  - spec/code2rubylearning_spec.rb
58
58
  - spec/spec_helper.rb
@@ -70,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  segments:
72
72
  - 0
73
- hash: -616480127
73
+ hash: -949178893
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  segments:
81
81
  - 0
82
- hash: -616480127
82
+ hash: -949178893
83
83
  requirements: []
84
84
  rubyforge_project:
85
85
  rubygems_version: 1.8.24
@@ -88,9 +88,10 @@ specification_version: 3
88
88
  summary: command line tool that formats, given source code files, making them ready
89
89
  for pasting to the rubylearning.org forum.
90
90
  test_files:
91
+ - spec/assets/file-1.rb
92
+ - spec/assets/file-2.rb
91
93
  - spec/code2rubylearning/filehandling_spec.rb
92
94
  - spec/code2rubylearning/filter_spec.rb
93
- - spec/code2rubylearning/parse_cli_spec.rb
94
95
  - spec/code2rubylearning/version_spec.rb
95
96
  - spec/code2rubylearning_spec.rb
96
97
  - spec/spec_helper.rb
@@ -1,23 +0,0 @@
1
- module Code2rubylearning
2
- module ParseCLI
3
-
4
- extend self
5
-
6
- attr_reader :files, :options
7
-
8
- def parse args
9
- @files = []
10
- @options = []
11
- @args = args
12
-
13
- @args.each do |arg|
14
- if arg.include?('-')
15
- @options << arg
16
- else
17
- @files << arg
18
- end
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "ParseCLI" do
4
- before :each do
5
- #
6
- end
7
-
8
- describe ".parse" do
9
- it "should parse command line into files and options" do
10
- cmd_line = ['file1.rb', '-b', '--help', 'file2.rb', 'file3.txt']
11
-
12
- expected_files = ['file1.rb', 'file2.rb', 'file3.txt']
13
- expected_options = ['-b', '--help']
14
- ParseCLI.parse cmd_line
15
- ParseCLI.files.must_equal expected_files
16
- ParseCLI.options.must_equal expected_options
17
- end
18
- end
19
-
20
- end