ngannotate-rails 0.15.4.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +60 -22
- data/lib/ngannotate/processor.rb +7 -47
- data/lib/ngannotate/processor3.rb +4 -49
- data/lib/ngannotate/processor_common.rb +113 -0
- data/lib/ngannotate/rails/railtie.rb +20 -4
- data/lib/ngannotate/rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eac5144784fb8fa889cb253acee99066f1f1d5a6
|
4
|
+
data.tar.gz: 67c565e93929dbdd1610e1cd8d8a2703a9c64e0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85a5293de6c2b712eb1867156f57b3838196659a6f5cd94797363aa13dd11cb7cde5b295b5257b68abc27a5df467f7548edad1a34c3ea1542075f21dddf143da
|
7
|
+
data.tar.gz: 98d464f59d5b05ac2db869491166a36cc2ed369a8da6dccfc16aa685836497e4eb265be8f8c67768ef0723c3203b94d19641fbfa710c70d303fac3ac77263303
|
data/README.md
CHANGED
@@ -21,31 +21,69 @@ Usage
|
|
21
21
|
|
22
22
|
By default ng-annotate processing is disabled in development and test environments. Processing, however, can be enforced by specifying NG_FORCE=true option.
|
23
23
|
|
24
|
+
### Environment options
|
24
25
|
|
25
|
-
|
26
|
+
- NG_REGEXP
|
27
|
+
* regexp passed to ng-annoate
|
28
|
+
* see ng-annotate documentation
|
29
|
+
- NG_OPT
|
30
|
+
* comma separate list of "opt=value" key pairs passed as options to ng-annotate
|
31
|
+
* see ng-annotate documentation
|
32
|
+
- NG_FORCE
|
33
|
+
* force ng-annoate processing in development/test environment
|
26
34
|
|
27
|
-
|
28
|
-
see ng-annotate documentation
|
29
|
-
NG_OPT - comma separate list of "opt=value" key pairs passed as options to ng-annotate
|
30
|
-
see ng-annotate documentation
|
31
|
-
NG_FORCE=true - force ng-annoate processing in development/test environment
|
35
|
+
For example,
|
32
36
|
|
33
|
-
|
37
|
+
# Test assets compile in rails development environment
|
38
|
+
# (assuming config/environments/development.rb is adjusted approriately)
|
39
|
+
|
40
|
+
# with rails 3.2
|
41
|
+
NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clean assets:precompile
|
42
|
+
|
43
|
+
# with rails 4.1
|
44
|
+
NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clobber assets:precompile
|
45
|
+
|
46
|
+
|
47
|
+
### Rails configuration options
|
48
|
+
|
49
|
+
Defined in "config.ng_annotate"
|
50
|
+
|
51
|
+
- process
|
52
|
+
* Is annotation processing done for current environment (NG_FORCE=true takes precedence over this)
|
53
|
+
* default: true for production, false for development and test
|
54
|
+
- options
|
55
|
+
* Options for ngannotate (NG_OPT and NG_REGEXP env variables take precedence over this)
|
56
|
+
* default: {}
|
57
|
+
- paths
|
58
|
+
* Asset paths, which are handled. Paths in ignore_paths override this setting
|
59
|
+
Values can be [String | Regexp | Proc] instances
|
60
|
+
* default: [/.*/]
|
61
|
+
- ignore_paths
|
62
|
+
* List of asset paths, which are ignored from ngannotate processing.
|
63
|
+
Values can be [String | Regexp | Proc] instances
|
64
|
+
* default: ['/vendor/']
|
65
|
+
|
66
|
+
For example,
|
34
67
|
|
35
68
|
config/environments/development.rb
|
36
69
|
|
37
70
|
Rails.application.configure do
|
38
71
|
...
|
39
72
|
config.ng_annotate.process = true
|
73
|
+
config.ng_annotate.options = {
|
74
|
+
key1: 'value',
|
75
|
+
regexp: '...',
|
76
|
+
}
|
77
|
+
config.ng_annotate.paths = [
|
78
|
+
Rails.root.to_s,
|
79
|
+
]
|
80
|
+
config.ng_annotate.ignore_paths = [
|
81
|
+
'/vendor/',
|
82
|
+
'/some/path/'
|
83
|
+
]
|
40
84
|
...
|
41
85
|
end
|
42
86
|
|
43
|
-
Examples,
|
44
|
-
|
45
|
-
# Test assets compile in rails development environment
|
46
|
-
# (assuming config/environments/development.rb is adjusted approriately)
|
47
|
-
NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clean assets:precompile
|
48
|
-
|
49
87
|
|
50
88
|
Testing assets locally
|
51
89
|
----------------------
|
@@ -76,18 +114,23 @@ precompile & start server
|
|
76
114
|
Versioning
|
77
115
|
----------
|
78
116
|
|
79
|
-
|
80
|
-
|
81
|
-
|
117
|
+
Originally version numbering of this gem followed ng-annoate. However, in order to improve
|
118
|
+
handling of possibly compatibility breaking fixes and improvements, version schema is now
|
119
|
+
separated from ng-annotate. Instead of matching versions, changelog in
|
120
|
+
[wiki](https://github.com/kikonen/ngannotate-rails/wiki) will indicate which is currently matching
|
121
|
+
ng-annotate version.
|
122
|
+
|
123
|
+
Every released version is tagged with tag "vX.Y.Z".
|
82
124
|
|
83
125
|
Release Process
|
84
126
|
---------------
|
85
127
|
|
86
|
-
For ngannotate update:
|
128
|
+
For ngannotate update (or any other improvements/fixes):
|
87
129
|
|
88
130
|
```bash
|
89
131
|
git checkout master
|
90
132
|
git pull
|
133
|
+
# if ngannotate update
|
91
134
|
rake ngannotate:build
|
92
135
|
git citool
|
93
136
|
# check that result makes sense and if so,
|
@@ -99,11 +142,6 @@ gem build ngannotate-rails.gemspec
|
|
99
142
|
gem push ngannotate-rails-X.Y.Z.gems
|
100
143
|
```
|
101
144
|
|
102
|
-
For internal fixes:
|
103
|
-
|
104
|
-
Similar except no ngannotate:build and new version is previous plus fourth digit for patch level (see Versioning).
|
105
|
-
|
106
|
-
|
107
145
|
Help
|
108
146
|
----
|
109
147
|
|
data/lib/ngannotate/processor.rb
CHANGED
@@ -1,57 +1,17 @@
|
|
1
1
|
require 'execjs'
|
2
2
|
require 'sprockets/processor'
|
3
|
+
require_relative 'processor_common'
|
3
4
|
|
4
5
|
module Ngannotate
|
5
6
|
class Processor < Sprockets::Processor
|
6
|
-
|
7
|
-
'Ngannotate::Processor'
|
8
|
-
end
|
9
|
-
|
10
|
-
def prepare
|
11
|
-
return if skip
|
12
|
-
ngannotate_source = File.open(File.join(File.dirname(__FILE__), '../../vendor/ngannotate.js')).read
|
13
|
-
@context = ExecJS.compile "window = {};" + ngannotate_source
|
14
|
-
end
|
15
|
-
|
16
|
-
#
|
17
|
-
# To allow testing assets compile in development environment
|
18
|
-
#
|
19
|
-
# To explicitly force assets compile in development environment
|
20
|
-
# NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clean assets:precompile
|
21
|
-
# or add to environments/development.rb
|
22
|
-
# config.ng_annotate.process = true
|
23
|
-
#
|
24
|
-
def force
|
25
|
-
ENV['NG_FORCE'] == 'true'
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Skip processing in environments where it does not make sense.
|
30
|
-
# Override by NG_FORCE=true env variable
|
31
|
-
#
|
32
|
-
def skip
|
33
|
-
!force && !::Rails.configuration.ng_annotate.process
|
34
|
-
end
|
7
|
+
include ProcessorCommon
|
35
8
|
|
36
9
|
def evaluate(context, locals)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def parse_opt
|
45
|
-
opt = {}
|
46
|
-
opt_str = ENV['NG_OPT']
|
47
|
-
if opt_str
|
48
|
-
opt = Hash[opt_str.split(',').map { |e| e.split('=') }]
|
49
|
-
opt.symbolize_keys!
|
50
|
-
end
|
51
|
-
if ENV['NG_REGEXP']
|
52
|
-
opt[:regexp] = ENV['NG_REGEXP']
|
53
|
-
end
|
54
|
-
opt
|
10
|
+
input = {
|
11
|
+
filename: @file,
|
12
|
+
data: data,
|
13
|
+
}
|
14
|
+
process_data(input)
|
55
15
|
end
|
56
16
|
end
|
57
17
|
end
|
@@ -1,65 +1,20 @@
|
|
1
1
|
require 'execjs'
|
2
|
+
require_relative 'processor_common'
|
2
3
|
|
3
4
|
module Ngannotate
|
4
5
|
class Processor
|
6
|
+
include ProcessorCommon
|
7
|
+
|
5
8
|
def self.instance
|
6
9
|
@instance ||= new
|
7
10
|
end
|
8
11
|
|
9
|
-
def self.name
|
10
|
-
'Ngannotate::Processor'
|
11
|
-
end
|
12
|
-
|
13
12
|
def self.call(input)
|
14
13
|
instance.call(input)
|
15
14
|
end
|
16
15
|
|
17
16
|
def call(input)
|
18
|
-
|
19
|
-
return data if skip
|
20
|
-
prepare
|
21
|
-
opt = { add: true }.merge!(parse_opt)
|
22
|
-
r = @context.call 'window.annotate', data, opt
|
23
|
-
r['src']
|
24
|
-
end
|
25
|
-
|
26
|
-
def prepare
|
27
|
-
return if skip
|
28
|
-
ngannotate_source = File.open(File.join(File.dirname(__FILE__), '../../vendor/ngannotate.js')).read
|
29
|
-
@context = ExecJS.compile "window = {};" + ngannotate_source
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# To allow testing assets compile in development environment
|
34
|
-
#
|
35
|
-
# To explicitly force assets compile in development environment
|
36
|
-
# NG_FORCE=true RAILS_ENV=development bundle exec rake assets:clean assets:precompile
|
37
|
-
# or add to environments/development.rb
|
38
|
-
# config.ng_annotate.process = true
|
39
|
-
#
|
40
|
-
def force
|
41
|
-
ENV['NG_FORCE'] == 'true'
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Skip processing in environments where it does not make sense.
|
46
|
-
# Override by NG_FORCE=true env variable
|
47
|
-
#
|
48
|
-
def skip
|
49
|
-
!force && !::Rails.configuration.ng_annotate.process
|
50
|
-
end
|
51
|
-
|
52
|
-
def parse_opt
|
53
|
-
opt = {}
|
54
|
-
opt_str = ENV['NG_OPT']
|
55
|
-
if opt_str
|
56
|
-
opt = Hash[opt_str.split(',').map { |e| e.split('=') }]
|
57
|
-
opt.symbolize_keys!
|
58
|
-
end
|
59
|
-
if ENV['NG_REGEXP']
|
60
|
-
opt[:regexp] = ENV['NG_REGEXP']
|
61
|
-
end
|
62
|
-
opt
|
17
|
+
process_data(input)
|
63
18
|
end
|
64
19
|
end
|
65
20
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Ngannotate
|
2
|
+
module ProcessorCommon
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def name
|
9
|
+
'Ngannotate::Processor'
|
10
|
+
end
|
11
|
+
|
12
|
+
def shared_exec_context
|
13
|
+
@shared_exec_context ||=
|
14
|
+
begin
|
15
|
+
::Rails.logger.info "ng-prepare"
|
16
|
+
ngannotate_source = File.open(File.expand_path('../../../vendor/ngannotate.js', __FILE__)).read
|
17
|
+
ExecJS.compile "window = {};" + ngannotate_source
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def logger
|
23
|
+
::Rails.logger
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_data(input)
|
27
|
+
data = input[:data]
|
28
|
+
file = input[:filename]
|
29
|
+
|
30
|
+
handle = need_process?(input)
|
31
|
+
state = handle ? :process : (ignore_file?(input) ? :ignore : :skip)
|
32
|
+
logger.info "ng-#{state}: #{file}"
|
33
|
+
return data unless handle
|
34
|
+
|
35
|
+
opt = { add: true }.merge!(parse_ngannotate_options)
|
36
|
+
r = exec_context.call 'window.annotate', data, opt
|
37
|
+
r['src']
|
38
|
+
end
|
39
|
+
|
40
|
+
def exec_context
|
41
|
+
@exec_context ||= self.class.shared_exec_context
|
42
|
+
end
|
43
|
+
|
44
|
+
def config
|
45
|
+
::Rails.configuration.ng_annotate
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Is processing done for current file. This is determined by 4 checks
|
50
|
+
#
|
51
|
+
# - config.paths
|
52
|
+
# - config.ignore_paths
|
53
|
+
# - config.process
|
54
|
+
# - NG_FORCE=true env option
|
55
|
+
#
|
56
|
+
def need_process?(input)
|
57
|
+
force_process = ENV['NG_FORCE'] == 'true'
|
58
|
+
process_file?(input) && (force_process || config.process)
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# @return true if current file should be processed
|
63
|
+
#
|
64
|
+
def process_file?(input)
|
65
|
+
!ignore_file?(input) && match_input(config.paths, input)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# @return true if current file is ignored
|
70
|
+
#
|
71
|
+
def ignore_file?(input)
|
72
|
+
match_input(config.ignore_paths, input)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# @return truthy value if input matches any of paths
|
77
|
+
#
|
78
|
+
def match_input(paths, input)
|
79
|
+
file = input[:filename]
|
80
|
+
paths.any? do |p|
|
81
|
+
if p.is_a? Proc
|
82
|
+
p.call(file)
|
83
|
+
elsif p.is_a? Regexp
|
84
|
+
p.match(file)
|
85
|
+
else
|
86
|
+
file.index(p)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Parse extra options for ngannotate
|
93
|
+
#
|
94
|
+
def parse_ngannotate_options
|
95
|
+
opt = config.options.clone
|
96
|
+
|
97
|
+
if ENV['NG_OPT']
|
98
|
+
opt_str = ENV['NG_OPT']
|
99
|
+
if opt_str
|
100
|
+
opt = Hash[opt_str.split(',').map { |e| e.split('=') }]
|
101
|
+
opt.symbolize_keys!
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
regexp = ENV['NG_REGEXP']
|
106
|
+
if regexp
|
107
|
+
opt[:regexp] = regexp
|
108
|
+
end
|
109
|
+
|
110
|
+
opt
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -8,11 +8,27 @@ end
|
|
8
8
|
module Ngannotate
|
9
9
|
module Rails
|
10
10
|
class Railtie < ::Rails::Railtie
|
11
|
-
config.
|
11
|
+
config.before_configuration do |app|
|
12
|
+
config.ng_annotate = ActiveSupport::OrderedOptions.new
|
13
|
+
ng = config.ng_annotate
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
# Establish static configuration defaults
|
16
|
+
|
17
|
+
# @see ngannotate
|
18
|
+
ng.options = {}
|
19
|
+
|
20
|
+
# Disabled by default in development and test environments
|
21
|
+
ng.process = !::Rails.env.development? && !::Rails.env.test?
|
22
|
+
|
23
|
+
# comma separate list of paths to only handle for annotation
|
24
|
+
# - ignore_paths entries are filtered out from this
|
25
|
+
ng.paths = [/.*/]
|
26
|
+
|
27
|
+
# comma separate list of paths to ignore from annotation
|
28
|
+
ng.ignore_paths = [
|
29
|
+
'/vendor/',
|
30
|
+
]
|
31
|
+
end
|
16
32
|
|
17
33
|
initializer "ngannotate-rails.add_ngannotate_postprocessor", :group => :all do |app|
|
18
34
|
app.assets.register_postprocessor 'application/javascript', Ngannotate::Processor
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ngannotate-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kari Ikonen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/ngannotate.rb
|
85
85
|
- lib/ngannotate/processor.rb
|
86
86
|
- lib/ngannotate/processor3.rb
|
87
|
+
- lib/ngannotate/processor_common.rb
|
87
88
|
- lib/ngannotate/rails.rb
|
88
89
|
- lib/ngannotate/rails/railtie.rb
|
89
90
|
- lib/ngannotate/rails/version.rb
|