strawberry_cough 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -7
- data/Gemfile.lock +66 -51
- data/README.md +9 -7
- data/Rakefile +4 -0
- data/config/flay.yml +4 -0
- data/config/flog.yml +3 -0
- data/config/site.reek +97 -0
- data/config/yardstick.yml +3 -0
- data/lib/assets/javascripts/routes.js.strawberry_cough +0 -0
- data/lib/strawberry_cough/path_compiler.rb +27 -10
- data/lib/strawberry_cough/path_parser.rb +18 -6
- data/lib/strawberry_cough/rails/engine.rb +15 -0
- data/lib/strawberry_cough/routes_compiler.rb +18 -1
- data/lib/strawberry_cough/routes_js_template.rb +15 -0
- data/lib/strawberry_cough/version.rb +2 -1
- data/lib/strawberry_cough.rb +2 -1
- data/spec/routes_compiler_spec.rb +6 -4
- data/strawberry_cough.gemspec +1 -1
- data/tags +184 -0
- data/tasks/ci.rake +3 -0
- data/tasks/quality/flay.rake +42 -0
- data/tasks/quality/flog.rake +44 -0
- data/tasks/quality/metric_fu.rake +26 -0
- data/tasks/quality/reek.rake +10 -0
- data/tasks/quality/yardstick.rake +24 -0
- metadata +47 -52
- data/lib/strawberry_cough/railtie.rb +0 -19
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@strawberry_cough
|
data/Gemfile
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org/'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rake'
|
5
|
+
gem 'rake'
|
6
6
|
|
7
|
-
gem 'activesupport', '~> 3.
|
8
|
-
gem 'railties',
|
7
|
+
gem 'activesupport', '~> 3.1'
|
8
|
+
gem 'railties', '~> 3.1'
|
9
|
+
gem 'tilt'
|
10
|
+
gem 'sprockets-rails'
|
9
11
|
|
10
12
|
group :test do
|
11
|
-
gem 'rspec'
|
12
|
-
gem 'therubyracer'
|
13
|
-
gem 'autotest', '~> 4.3.2'
|
13
|
+
gem 'rspec'
|
14
|
+
gem 'therubyracer'
|
14
15
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,67 +1,82 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strawberry_cough (0.
|
4
|
+
strawberry_cough (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
rack (~> 1.
|
17
|
-
rack-mount (~> 0.
|
18
|
-
rack-test (~> 0.
|
19
|
-
|
20
|
-
activemodel (3.
|
21
|
-
activesupport (= 3.
|
22
|
-
builder (~>
|
23
|
-
i18n (~> 0.
|
24
|
-
activesupport (3.
|
25
|
-
|
26
|
-
builder (
|
27
|
-
diff-lcs (1.1.
|
28
|
-
erubis (2.
|
29
|
-
|
30
|
-
i18n (0.
|
31
|
-
|
32
|
-
|
9
|
+
actionpack (3.1.1)
|
10
|
+
activemodel (= 3.1.1)
|
11
|
+
activesupport (= 3.1.1)
|
12
|
+
builder (~> 3.0.0)
|
13
|
+
erubis (~> 2.7.0)
|
14
|
+
i18n (~> 0.6)
|
15
|
+
rack (~> 1.3.2)
|
16
|
+
rack-cache (~> 1.1)
|
17
|
+
rack-mount (~> 0.8.2)
|
18
|
+
rack-test (~> 0.6.1)
|
19
|
+
sprockets (~> 2.0.2)
|
20
|
+
activemodel (3.1.1)
|
21
|
+
activesupport (= 3.1.1)
|
22
|
+
builder (~> 3.0.0)
|
23
|
+
i18n (~> 0.6)
|
24
|
+
activesupport (3.1.1)
|
25
|
+
multi_json (~> 1.0)
|
26
|
+
builder (3.0.0)
|
27
|
+
diff-lcs (1.1.3)
|
28
|
+
erubis (2.7.0)
|
29
|
+
hike (1.2.1)
|
30
|
+
i18n (0.6.0)
|
31
|
+
json (1.6.1)
|
32
|
+
multi_json (1.0.3)
|
33
|
+
rack (1.3.5)
|
34
|
+
rack-cache (1.1)
|
35
|
+
rack (>= 0.4)
|
36
|
+
rack-mount (0.8.3)
|
33
37
|
rack (>= 1.0.0)
|
34
|
-
rack-
|
38
|
+
rack-ssl (1.3.2)
|
39
|
+
rack
|
40
|
+
rack-test (0.6.1)
|
35
41
|
rack (>= 1.0)
|
36
|
-
railties (3.
|
37
|
-
actionpack (= 3.
|
38
|
-
activesupport (= 3.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
rspec
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
railties (3.1.1)
|
43
|
+
actionpack (= 3.1.1)
|
44
|
+
activesupport (= 3.1.1)
|
45
|
+
rack-ssl (~> 1.3.2)
|
46
|
+
rake (>= 0.8.7)
|
47
|
+
rdoc (~> 3.4)
|
48
|
+
thor (~> 0.14.6)
|
49
|
+
rake (0.9.2.2)
|
50
|
+
rdoc (3.11)
|
51
|
+
json (~> 1.4)
|
52
|
+
rspec (2.7.0)
|
53
|
+
rspec-core (~> 2.7.0)
|
54
|
+
rspec-expectations (~> 2.7.0)
|
55
|
+
rspec-mocks (~> 2.7.0)
|
56
|
+
rspec-core (2.7.1)
|
57
|
+
rspec-expectations (2.7.0)
|
58
|
+
diff-lcs (~> 1.1.2)
|
59
|
+
rspec-mocks (2.7.0)
|
60
|
+
sprockets (2.0.3)
|
61
|
+
hike (~> 1.2)
|
62
|
+
rack (~> 1.0)
|
63
|
+
tilt (~> 1.1, != 1.3.0)
|
64
|
+
sprockets-rails (0.0.1)
|
65
|
+
sprockets (>= 1.0.2)
|
66
|
+
therubyracer (0.8.1)
|
67
|
+
thor (0.14.6)
|
68
|
+
tilt (1.3.3)
|
55
69
|
|
56
70
|
PLATFORMS
|
57
71
|
ruby
|
58
72
|
|
59
73
|
DEPENDENCIES
|
60
|
-
activesupport (~> 3.
|
61
|
-
autotest (~> 4.3.2)
|
74
|
+
activesupport (~> 3.1)
|
62
75
|
bundler (>= 1.0.0)
|
63
|
-
railties (~> 3.
|
64
|
-
rake
|
65
|
-
rspec
|
76
|
+
railties (~> 3.1)
|
77
|
+
rake
|
78
|
+
rspec
|
79
|
+
sprockets-rails
|
66
80
|
strawberry_cough!
|
67
|
-
therubyracer
|
81
|
+
therubyracer
|
82
|
+
tilt
|
data/README.md
CHANGED
@@ -28,16 +28,18 @@ To install, just add the following line to your Gemfile.
|
|
28
28
|
|
29
29
|
gem 'strawberry_cough'
|
30
30
|
|
31
|
-
Then
|
31
|
+
Then `//= require routes` in the JavaScript manifest file.
|
32
|
+
|
33
|
+
If you want a differently named JavaScript file add
|
34
|
+
`somefile.js.strawberry_cough` to your javascript assets.
|
32
35
|
|
33
36
|
Notes
|
34
37
|
-----
|
35
38
|
|
36
|
-
Right now, Strawberry Cough is **Rails 3 only**.
|
37
|
-
|
38
|
-
A file `public/javascripts/routes.js` will be generated on each request to your app in the development environment, and on the first request only in production.
|
39
|
+
Right now, Strawberry Cough is **Rails 3.1 only**.
|
39
40
|
|
40
|
-
It uses
|
41
|
+
It uses Rails' asset pipeline to generate the route file.
|
42
|
+
In development/test environments add config.assets.compile=true.
|
41
43
|
|
42
44
|
Authors
|
43
45
|
-------
|
@@ -48,7 +50,7 @@ Authors
|
|
48
50
|
License
|
49
51
|
-------
|
50
52
|
|
51
|
-
Copyright
|
53
|
+
Copyright 2011, Three Wise Men Inc. All rights reserved.
|
52
54
|
|
53
55
|
Redistribution and use in source and binary forms, with or without
|
54
56
|
modification, are permitted provided that the following conditions are met:
|
@@ -75,4 +77,4 @@ The views and conclusions contained in the software and documentation are
|
|
75
77
|
those of the authors and should not be interpreted as representing official
|
76
78
|
policies, either expressed or implied, of Three Wise Men Inc.
|
77
79
|
|
78
|
-
[1]: http://api.rubyonrails.org/classes/Rails/Railtie.html "Railties docs"
|
80
|
+
[1]: http://api.rubyonrails.org/classes/Rails/Railtie.html "Railties docs"
|
data/Rakefile
CHANGED
data/config/flay.yml
ADDED
data/config/flog.yml
ADDED
data/config/site.reek
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
---
|
2
|
+
UncommunicativeParameterName:
|
3
|
+
accept: []
|
4
|
+
exclude: []
|
5
|
+
enabled: true
|
6
|
+
reject:
|
7
|
+
- !ruby/regexp /^.$/
|
8
|
+
- !ruby/regexp /[0-9]$/
|
9
|
+
- !ruby/regexp /[A-Z]/
|
10
|
+
LargeClass:
|
11
|
+
max_methods: 16 # TODO: decrease max_methods to 10-15 or less
|
12
|
+
exclude: []
|
13
|
+
enabled: true
|
14
|
+
max_instance_variables: 3
|
15
|
+
UncommunicativeMethodName:
|
16
|
+
accept: []
|
17
|
+
exclude: []
|
18
|
+
enabled: true
|
19
|
+
reject:
|
20
|
+
- !ruby/regexp /^[a-z]$/
|
21
|
+
- !ruby/regexp /[0-9]$/
|
22
|
+
- !ruby/regexp /[A-Z]/
|
23
|
+
LongParameterList:
|
24
|
+
max_params: 2 # TODO: decrease max_params to 2
|
25
|
+
exclude: []
|
26
|
+
enabled: true
|
27
|
+
overrides: {}
|
28
|
+
FeatureEnvy:
|
29
|
+
exclude: []
|
30
|
+
enabled: true
|
31
|
+
ClassVariable:
|
32
|
+
exclude: []
|
33
|
+
enabled: true
|
34
|
+
BooleanParameter:
|
35
|
+
exclude: []
|
36
|
+
enabled: true
|
37
|
+
IrresponsibleModule:
|
38
|
+
exclude: []
|
39
|
+
enabled: true
|
40
|
+
UncommunicativeModuleName:
|
41
|
+
accept: []
|
42
|
+
exclude: []
|
43
|
+
enabled: true
|
44
|
+
reject:
|
45
|
+
- !ruby/regexp /^.$/
|
46
|
+
- !ruby/regexp /[0-9]$/
|
47
|
+
NestedIterators:
|
48
|
+
ignore_iterators: []
|
49
|
+
exclude: []
|
50
|
+
enabled: true
|
51
|
+
max_allowed_nesting: 1
|
52
|
+
LongMethod:
|
53
|
+
max_statements: 7 # TODO: decrease max_statements to 5 or less
|
54
|
+
exclude: []
|
55
|
+
enabled: true
|
56
|
+
Duplication:
|
57
|
+
allow_calls: []
|
58
|
+
exclude: []
|
59
|
+
enabled: true
|
60
|
+
max_calls: 1
|
61
|
+
UtilityFunction:
|
62
|
+
max_helper_calls: 1
|
63
|
+
exclude: []
|
64
|
+
enabled: true
|
65
|
+
Attribute:
|
66
|
+
exclude: []
|
67
|
+
enabled: false
|
68
|
+
UncommunicativeVariableName:
|
69
|
+
accept: []
|
70
|
+
exclude: []
|
71
|
+
enabled: true
|
72
|
+
reject:
|
73
|
+
- !ruby/regexp /^.$/
|
74
|
+
- !ruby/regexp /[0-9]$/
|
75
|
+
- !ruby/regexp /[A-Z]/
|
76
|
+
SimulatedPolymorphism:
|
77
|
+
exclude: []
|
78
|
+
enabled: true
|
79
|
+
max_ifs: 1
|
80
|
+
DataClump:
|
81
|
+
exclude: [
|
82
|
+
# all of these classes have utility class methods that are
|
83
|
+
# incorrectly identified as instance methods
|
84
|
+
Veritas::Relation::Operation::Binary::ClassMethods,
|
85
|
+
Veritas::Relation::Operation::Set::ClassMethods
|
86
|
+
]
|
87
|
+
enabled: true
|
88
|
+
max_copies: 1
|
89
|
+
min_clump_size: 2
|
90
|
+
ControlCouple:
|
91
|
+
exclude: []
|
92
|
+
enabled: true
|
93
|
+
LongYieldList:
|
94
|
+
max_params: 1
|
95
|
+
exclude: []
|
96
|
+
enabled: true
|
97
|
+
|
File without changes
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module StrawberryCough
|
2
2
|
|
3
|
+
# Compiles a path to a JavaScript function
|
3
4
|
class PathCompiler
|
4
5
|
|
6
|
+
# Compile path to JavaScript function
|
7
|
+
#
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
# @api private
|
5
11
|
def self.compile(path)
|
6
12
|
params = PathParser.parse_params(path)
|
7
13
|
anchors = PathParser.parse_anchors(path)
|
@@ -19,16 +25,27 @@ function (#{args_list(params)}) {
|
|
19
25
|
end
|
20
26
|
|
21
27
|
private
|
22
|
-
def self.url_concatenation(anchors, params)
|
23
|
-
params_without_format = params.reject { |p| p == "format" }
|
24
|
-
quoted_anchors = anchors.map { |a| "\"#{a}\"" }
|
25
|
-
anchors_paired_with_params = quoted_anchors.zip(params_without_format)
|
26
|
-
anchors_paired_with_params.flatten.compact.join(" + ")
|
27
|
-
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
# Generate JavaScript to concatenate anchors and params into valid URL
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
def self.url_concatenation(anchors, params)
|
35
|
+
params_without_format = params.reject { |param| param == "format" }
|
36
|
+
quoted_anchors = anchors.map { |anchor| "\"#{anchor}\"" }
|
37
|
+
quoted_anchors.zip(params_without_format).flatten.compact.join(" + ")
|
38
|
+
end
|
39
|
+
|
33
40
|
|
41
|
+
# Generate argument listing for JavaScript function
|
42
|
+
#
|
43
|
+
# @return [String]
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
def self.args_list(params)
|
47
|
+
params.join(", ")
|
48
|
+
end
|
49
|
+
end
|
34
50
|
end
|
51
|
+
|
@@ -1,18 +1,30 @@
|
|
1
1
|
module StrawberryCough
|
2
2
|
|
3
|
+
# Parses a path into anchors and parameters
|
3
4
|
class PathParser
|
5
|
+
PARAM_EXTRACTOR_PATTERN = /:([\w_\d]+)\(*/
|
6
|
+
ANCHOR_SPLIT_PATTERN = /:[\w_\d]+/
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
+
# Get list of parameters from a path
|
9
|
+
#
|
10
|
+
# @return [Array]
|
11
|
+
#
|
12
|
+
# @api private
|
8
13
|
def self.parse_params(path)
|
9
|
-
path.scan(
|
14
|
+
path.scan(PARAM_EXTRACTOR_PATTERN).flatten
|
10
15
|
end
|
11
16
|
|
17
|
+
# Get list of anchors from a path
|
18
|
+
#
|
19
|
+
# @return [Array]
|
20
|
+
#
|
21
|
+
# @api private
|
12
22
|
def self.parse_anchors(path)
|
13
|
-
path
|
23
|
+
remove_format(path).split(ANCHOR_SPLIT_PATTERN)
|
14
24
|
end
|
15
25
|
|
26
|
+
def self.remove_format(path)
|
27
|
+
path.gsub(/\(.*\)/, '')
|
28
|
+
end
|
16
29
|
end
|
17
|
-
|
18
30
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'strawberry_cough/routes_compiler'
|
2
|
+
require 'rails/engine'
|
3
|
+
|
4
|
+
module StrawberryCough
|
5
|
+
module Rails
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
config.before_initialize do
|
8
|
+
if defined?(Sprockets::Engines)
|
9
|
+
Sprockets::Engines
|
10
|
+
Sprockets.register_engine '.strawberry_cough', RoutesJSTemplate
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,14 +1,22 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
+
require 'active_support/core_ext'
|
2
3
|
|
3
4
|
module StrawberryCough
|
4
5
|
|
6
|
+
# Compiles a set of routes to a JavaScript Routes object
|
5
7
|
class RoutesCompiler
|
6
8
|
|
9
|
+
# Compile route set to a JavaScript object
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
#
|
13
|
+
# @api private
|
7
14
|
def self.compile(route_set)
|
8
|
-
functions = route_set.inject(Set.new) do |memo, route|
|
15
|
+
functions = named_routes(route_set).inject(Set.new) do |memo, route|
|
9
16
|
name = route.name.camelize(:lower) + "Path"
|
10
17
|
memo << "#{name} : " + PathCompiler.compile(route.path)
|
11
18
|
end.to_a.join(',')
|
19
|
+
|
12
20
|
<<-COMPILED
|
13
21
|
var Routes = {
|
14
22
|
#{functions}
|
@@ -16,9 +24,18 @@ var Routes = {
|
|
16
24
|
COMPILED
|
17
25
|
end
|
18
26
|
|
27
|
+
# Write set to IO object
|
28
|
+
#
|
29
|
+
# @return [IO]
|
30
|
+
#
|
31
|
+
# @api private
|
19
32
|
def self.compile_to_io(route_set, io)
|
20
33
|
io << compile(route_set)
|
21
34
|
end
|
22
35
|
|
36
|
+
def self.named_routes(routes)
|
37
|
+
routes.select {|x| x.name.present? }
|
38
|
+
end
|
23
39
|
end
|
24
40
|
end
|
41
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'tilt/template'
|
2
|
+
require 'strawberry_cough/routes_compiler'
|
3
|
+
|
4
|
+
module StrawberryCough
|
5
|
+
class RoutesJSTemplate < Tilt::Template
|
6
|
+
|
7
|
+
def prepare
|
8
|
+
end
|
9
|
+
|
10
|
+
def render(scope=Object.new, locals={}, &block)
|
11
|
+
route_set = ::Rails.application.routes
|
12
|
+
RoutesCompiler.compile(route_set.routes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/strawberry_cough.rb
CHANGED
@@ -2,4 +2,5 @@ require 'strawberry_cough/version'
|
|
2
2
|
require 'strawberry_cough/path_compiler'
|
3
3
|
require 'strawberry_cough/path_parser'
|
4
4
|
require 'strawberry_cough/routes_compiler'
|
5
|
-
require 'strawberry_cough/
|
5
|
+
require 'strawberry_cough/rails/engine'
|
6
|
+
require 'strawberry_cough/routes_js_template'
|
@@ -4,10 +4,11 @@ describe StrawberryCough::RoutesCompiler do
|
|
4
4
|
let(:compiler) { StrawberryCough::RoutesCompiler }
|
5
5
|
let(:interpreter) { V8::Context.new }
|
6
6
|
|
7
|
-
it "
|
8
|
-
|
9
|
-
interpreter.eval(
|
10
|
-
|
7
|
+
it "generates an empty Routes object with an empty route set" do
|
8
|
+
empty_routes_object = compiler.compile([])
|
9
|
+
interpreter.eval(empty_routes_object)
|
10
|
+
property_check = "for (var prop in Routes) { return prop; }"
|
11
|
+
interpreter.eval(property_check).should be_nil
|
11
12
|
end
|
12
13
|
|
13
14
|
it "makes a Routes JavaScript object when given an array of routes" do
|
@@ -19,3 +20,4 @@ describe StrawberryCough::RoutesCompiler do
|
|
19
20
|
interpreter.eval("typeof Routes.editParentPath === 'function'").should be_true
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
data/strawberry_cough.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = "strawberry_cough"
|
6
6
|
s.version = StrawberryCough::VERSION
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.authors = ["Craig Savolainen", "Nate Smith"]
|
8
|
+
s.authors = ["Craig Savolainen", "Nate Smith", "Shawn Lee-Kwong"]
|
9
9
|
s.email = ["support@threewisemen.ca"]
|
10
10
|
s.homepage = "http://github.com/ThreeWiseMen/strawberry_cough"
|
11
11
|
s.summary = "Strawberry Cough lets you access your Rails 3 routes in your JavaScripts."
|