code2rubylearning 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -4
- data/Guardfile +1 -31
- data/README.md +4 -0
- data/bin/code2rubylearning +6 -0
- data/config.yaml.example +10 -0
- data/lib/code2rubylearning/filehandling.rb +22 -16
- data/lib/code2rubylearning/filter.rb +12 -7
- data/lib/code2rubylearning/version.rb +1 -1
- data/lib/code2rubylearning.rb +5 -4
- data/spec/code2rubylearning/filehandling_spec.rb +42 -1
- data/spec/code2rubylearning/filter_spec.rb +22 -6
- data/spec/spec_helper.rb +13 -9
- metadata +5 -4
data/.gitignore
CHANGED
data/Guardfile
CHANGED
@@ -1,28 +1,6 @@
|
|
1
1
|
# A sample Guardfile
|
2
2
|
# More info at https://github.com/guard/guard#readme
|
3
3
|
|
4
|
-
# guard 'rspec' do
|
5
|
-
# watch(%r{^spec/.+_spec\.rb$})
|
6
|
-
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
-
# watch('spec/spec_helper.rb') { "spec" }
|
8
|
-
|
9
|
-
# Rails example
|
10
|
-
# watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
-
# watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
-
# watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
-
# watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
-
# watch('config/routes.rb') { "spec/routing" }
|
15
|
-
# watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
-
|
17
|
-
# Capybara features specs
|
18
|
-
# watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
19
|
-
|
20
|
-
# Turnip features and steps
|
21
|
-
# watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
-
# watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
-
# end
|
24
|
-
|
25
|
-
|
26
4
|
guard 'minitest' do
|
27
5
|
# with Minitest::Unit
|
28
6
|
# watch(%r|^test/(.*)\/?test_(.*)\.rb|)
|
@@ -33,14 +11,6 @@ guard 'minitest' do
|
|
33
11
|
watch(%r|^spec/(.*)_spec\.rb|)
|
34
12
|
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
35
13
|
watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
14
|
+
watch(%r|^config.yaml|) { "spec" }
|
36
15
|
|
37
|
-
# Rails 3.2
|
38
|
-
# watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
|
39
|
-
# watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
|
40
|
-
# watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
|
41
|
-
|
42
|
-
# Rails
|
43
|
-
# watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
|
44
|
-
# watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
|
45
|
-
# watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
|
46
16
|
end
|
data/README.md
CHANGED
@@ -31,6 +31,10 @@ For more, see the [Usage Examples](https://github.com/rudicode/code2rubylearning
|
|
31
31
|
|
32
32
|
Do `bundle install`
|
33
33
|
|
34
|
+
copy `config.yaml.example` to `config.yaml`
|
35
|
+
|
36
|
+
edit `config.yaml` to your preferred testing reporter
|
37
|
+
|
34
38
|
To run minitest specs
|
35
39
|
`bundle exec rake spec`
|
36
40
|
|
data/bin/code2rubylearning
CHANGED
data/config.yaml.example
ADDED
@@ -1,28 +1,34 @@
|
|
1
1
|
module Code2rubylearning
|
2
2
|
class FileHandling
|
3
|
-
def initialize(file)
|
4
|
-
load_data file
|
5
|
-
end
|
6
3
|
|
7
|
-
|
8
|
-
@data
|
9
|
-
end
|
4
|
+
attr_reader :data, :name, :type
|
10
5
|
|
11
|
-
def
|
12
|
-
|
13
|
-
@data
|
6
|
+
def initialize(file_name, options = { })
|
7
|
+
@name = nil
|
8
|
+
@data = ""
|
9
|
+
@type = ""
|
10
|
+
load_data file_name
|
11
|
+
identify_file_type if @name
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@data = IO.read(@file)
|
14
|
+
def load_data file_name
|
15
|
+
|
16
|
+
if file_name
|
17
|
+
if File.exists?(file_name)
|
18
|
+
@name = file_name
|
19
|
+
@data = IO.read(@name)
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
24
|
+
# TODO
|
25
|
+
# Sets the @type for this file
|
26
|
+
# check extension for known types
|
27
|
+
# if extension fails try checking the first line
|
28
|
+
# it may contain #! and give a clue.
|
29
|
+
def identify_file_type
|
30
|
+
@type = "ruby"
|
31
|
+
end
|
32
|
+
|
27
33
|
end
|
28
34
|
end
|
@@ -1,16 +1,19 @@
|
|
1
1
|
module Code2rubylearning
|
2
2
|
class Filter
|
3
|
-
def initialize options
|
4
|
-
@
|
3
|
+
def initialize current_file, options
|
4
|
+
@current_file = current_file
|
5
|
+
@options = options
|
5
6
|
end
|
6
7
|
|
7
|
-
def apply input, file_name
|
8
|
-
add_header(file_name) << convert(input) << add_footer
|
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
|
9
11
|
end
|
10
12
|
|
11
13
|
def add_header file_name
|
12
|
-
|
13
|
-
header
|
14
|
+
type = @current_file.type
|
15
|
+
header = "[code #{ type }]\n"
|
16
|
+
header << "#filename: #{ file_name }\n" if @options[:filenames]
|
14
17
|
header
|
15
18
|
end
|
16
19
|
|
@@ -19,7 +22,9 @@ module Code2rubylearning
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def convert source
|
22
|
-
source.gsub('<','<')
|
25
|
+
source = source.gsub('<', '<')
|
26
|
+
source = source.gsub('>', '>')
|
27
|
+
source = source.gsub('Person', 'People')
|
23
28
|
end
|
24
29
|
|
25
30
|
end
|
data/lib/code2rubylearning.rb
CHANGED
@@ -11,10 +11,11 @@ module Code2rubylearning
|
|
11
11
|
@buffer = ""
|
12
12
|
|
13
13
|
files.each do |file|
|
14
|
-
current_file = FileHandling.new(file)
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
current_file = FileHandling.new(file, options)
|
15
|
+
if current_file.name
|
16
|
+
filter = Filter.new(current_file, options)
|
17
|
+
@buffer << filter.apply
|
18
|
+
end
|
18
19
|
end
|
19
20
|
|
20
21
|
if options[:prg_link]
|
@@ -1,7 +1,48 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "FileHandling" do
|
4
|
+
describe "valid files" do
|
5
|
+
before :each do
|
6
|
+
@valid_file_name = "spec/assets/file-1.rb"
|
7
|
+
@valid_file = FileHandling.new(@valid_file_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should set the name of the file" do
|
11
|
+
@valid_file.name.must_equal @valid_file_name
|
12
|
+
end
|
4
13
|
|
5
|
-
|
14
|
+
it "should set the data to the contents of the file" do
|
15
|
+
expected = "def hello\n \"Hello\"\nend\n"
|
16
|
+
@valid_file.data.must_equal expected
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should set the type to the correct programming language" do
|
20
|
+
expected = "ruby"
|
21
|
+
@valid_file.type.must_equal expected
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "invalid files" do
|
26
|
+
|
27
|
+
before :each do
|
28
|
+
@invalid_file_name = "spec/assets/file_does_not_exist"
|
29
|
+
@invalid_file = FileHandling.new(@invalid_file_name)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should set the name to nil" do
|
33
|
+
@invalid_file.name.must_equal nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should set the data to empty string" do
|
37
|
+
expected = ""
|
38
|
+
@invalid_file.data.must_equal expected
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set the type to empty string" do
|
42
|
+
expected = ""
|
43
|
+
@invalid_file.type.must_equal expected
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
6
47
|
|
7
48
|
end
|
@@ -3,7 +3,8 @@ require "spec_helper"
|
|
3
3
|
describe "Filter" do
|
4
4
|
before :each do
|
5
5
|
@options = {}
|
6
|
-
@
|
6
|
+
@original_file = FileHandling.new("spec/assets/file-1/rb")
|
7
|
+
@filter = Filter.new(@original_file, @options)
|
7
8
|
end
|
8
9
|
|
9
10
|
describe ".convert" do
|
@@ -19,21 +20,36 @@ describe "Filter" do
|
|
19
20
|
@filter.convert(original).must_equal expected
|
20
21
|
end
|
21
22
|
|
23
|
+
it "should convert single > to > in a string" do
|
24
|
+
original = 'class Automobile > Vehicle'
|
25
|
+
expected = 'class Automobile > Vehicle'
|
26
|
+
@filter.convert(original).must_equal expected
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should convert multiple >> to >> in a string" do
|
30
|
+
original = 'my_array >> "some string"'
|
31
|
+
expected = 'my_array >> "some string"'
|
32
|
+
@filter.convert(original).must_equal expected
|
33
|
+
end
|
34
|
+
|
22
35
|
end
|
23
36
|
|
24
37
|
describe ".apply" do
|
38
|
+
before :each do
|
39
|
+
@options = {}
|
40
|
+
@original_file = FileHandling.new("spec/assets/file-1.rb")
|
41
|
+
@filter = Filter.new(@original_file, @options)
|
42
|
+
end
|
43
|
+
|
25
44
|
it "should add [code ruby] to original string" do
|
26
|
-
original = "class Automobile < Vehicle\n #comment\nend"
|
27
45
|
expected = "[code ruby]\n"
|
28
|
-
@filter.apply
|
46
|
+
@filter.apply.must_include expected
|
29
47
|
end
|
30
48
|
|
31
49
|
it "should add [/code] to original string" do
|
32
|
-
original = "class Automobile < Vehicle\n #comment\nend"
|
33
50
|
expected = "[/code]\n"
|
34
|
-
@filter.apply
|
51
|
+
@filter.apply.must_include expected
|
35
52
|
end
|
36
|
-
|
37
53
|
end
|
38
54
|
|
39
55
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,16 +6,20 @@ require "bundler/setup"
|
|
6
6
|
require 'minitest/autorun'
|
7
7
|
require 'minitest/reporters'
|
8
8
|
require "minitest/matchers"
|
9
|
+
require 'yaml'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
begin
|
12
|
+
choice = YAML.load_file( 'config.yaml' )
|
13
|
+
MiniTest::Reporters.use!(eval("MiniTest::Reporters::#{choice}Reporter.new"))
|
14
|
+
rescue NameError, Errno::ENOENT
|
15
|
+
STDERR.puts <<-EOWARNING
|
16
|
+
#{'+-' * 33}
|
17
|
+
You either don't have a config.yaml file in your project root, or
|
18
|
+
you need to uncomment one of the choices from the menu.
|
19
|
+
#{'+-' * 33}
|
20
|
+
EOWARNING
|
21
|
+
raise
|
22
|
+
end
|
19
23
|
require('code2rubylearning')
|
20
24
|
require('code2rubylearning/version')
|
21
25
|
|
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.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clippy
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- Rakefile
|
46
46
|
- bin/code2rubylearning
|
47
47
|
- code2rubylearning.gemspec
|
48
|
+
- config.yaml.example
|
48
49
|
- lib/code2rubylearning.rb
|
49
50
|
- lib/code2rubylearning/filehandling.rb
|
50
51
|
- lib/code2rubylearning/filter.rb
|
@@ -70,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
71
|
version: '0'
|
71
72
|
segments:
|
72
73
|
- 0
|
73
|
-
hash: -
|
74
|
+
hash: -332398925
|
74
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
76
|
none: false
|
76
77
|
requirements:
|
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
version: '0'
|
80
81
|
segments:
|
81
82
|
- 0
|
82
|
-
hash: -
|
83
|
+
hash: -332398925
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project:
|
85
86
|
rubygems_version: 1.8.24
|