angumine 0.0.1
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 +15 -0
- data/LICENSE +19 -0
- data/README.md +60 -0
- data/bin/angumine +9 -0
- data/lib/angumine.rb +15 -0
- data/lib/angumine/cli.rb +74 -0
- data/lib/angumine/sax_parser.rb +70 -0
- data/lib/angumine/version.rb +3 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzhlNzUxZmRhMzAxYmUxYmM3MzExZWUyY2I5ZjNhM2FiNjU0NGQxMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWQwMzk0OGY0Njc0YWQ2ZmFiY2ExMjAzYTk5YmQ0OWY5NzE2MDQ5Zg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmIwOTZiZWM0Y2RmMzdiOGE2ZTAwOWIzNTFiNmJlZmQxZDgxZjE3YjQ4MDUz
|
10
|
+
NjRiYTU0OWMzMTM1OTJlYmIwOThlZTNmYjQ2MGU2ZGM2ODYxNzFmMzY5MjZm
|
11
|
+
YzU0YTE1OWExMTVmYTdmMjU0MWQ3ZGFkYzZmNDUwZmY0YjgxZmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDdmMzNiNTRjM2EyZWFhYmY0M2Q2MGYyNGEyNWRlMWJhNTQ5Y2FkNWNhYjY2
|
14
|
+
Zjk0OTI3YWE2YWM3YjQxN2FmOWYwOTBmYzZlNDZkM2NhMTYyZTNhNzYxOTcx
|
15
|
+
MjI3ZmY2Njg5M2E5ODkzZDQ3NWU2MjU5OGU5OTY1Y2Q0Nzc1YmM=
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Gary S. Weaver
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
Angumine
|
2
|
+
=====
|
3
|
+
|
4
|
+
Angumine is a simple command-line utility to parse AngularJS HTML templates for `ng-*` and handlebars (`{{...}}`) references to data that builds a dot-notated tree using loop structures found in the template, i.e. if the template contains:
|
5
|
+
|
6
|
+
```html
|
7
|
+
{{something.here}}
|
8
|
+
<beautifullist ng-class="ngClassesAreIgnored" ng-repeat="project in projects">
|
9
|
+
<documents ng-repeat="paper in project.papers">
|
10
|
+
<docbody ng-show="paper.visible">
|
11
|
+
{{paper.text}}
|
12
|
+
{{another.thing}}
|
13
|
+
</docbody>
|
14
|
+
</documents>
|
15
|
+
</beautifullist>
|
16
|
+
```
|
17
|
+
|
18
|
+
The output would be:
|
19
|
+
```
|
20
|
+
$ angumine test.html
|
21
|
+
|
22
|
+
---------
|
23
|
+
test.html
|
24
|
+
---------
|
25
|
+
|
26
|
+
something.here
|
27
|
+
[projects]project.[project.papers]paper.visible
|
28
|
+
[projects]project.[project.papers]paper.text
|
29
|
+
another.thing
|
30
|
+
```
|
31
|
+
|
32
|
+
### Installation
|
33
|
+
|
34
|
+
```
|
35
|
+
gem install angumine
|
36
|
+
```
|
37
|
+
|
38
|
+
### Usage
|
39
|
+
|
40
|
+
```
|
41
|
+
angumine file_or_dir_1 file_or_dir_2 file_or_dir_3
|
42
|
+
```
|
43
|
+
|
44
|
+
Or
|
45
|
+
|
46
|
+
```
|
47
|
+
angumine -r file_or_dir_to_search_recursively_1 file_or_dir_to_search_recursively_2
|
48
|
+
```
|
49
|
+
|
50
|
+
e.g.
|
51
|
+
|
52
|
+
```
|
53
|
+
angumine -r app/assets/templates/
|
54
|
+
```
|
55
|
+
|
56
|
+
### License
|
57
|
+
|
58
|
+
Copyright (c) 2013 Gary S. Weaver, released under the [MIT license][lic].
|
59
|
+
|
60
|
+
[lic]: http://github.com/garysweaver/angumine/blob/master/LICENSE
|
data/bin/angumine
ADDED
data/lib/angumine.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'angumine/version'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'angumine/cli'
|
4
|
+
require 'angumine/sax_parser'
|
5
|
+
|
6
|
+
module Angumine
|
7
|
+
class << self
|
8
|
+
def parse(file_contents)
|
9
|
+
sax_parser = Angumine::SaxParser.new
|
10
|
+
parser = Nokogiri::HTML::SAX::Parser.new(sax_parser)
|
11
|
+
parser.parse(file_contents)
|
12
|
+
sax_parser.mined_data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/angumine/cli.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'angumine'
|
2
|
+
|
3
|
+
# angumine
|
4
|
+
#
|
5
|
+
# Finds references to models in AngularJS and attempts to keep track of ng-repeat, etc. to build a tree.
|
6
|
+
# This may be helpful if you are trying to determine the JSON views required.
|
7
|
+
#
|
8
|
+
# Mines Angular Templates for model information.
|
9
|
+
module Angumine
|
10
|
+
class CLI
|
11
|
+
|
12
|
+
def self.fail
|
13
|
+
raise ArgumentError.new("Usage: angumine [-r] path_or_file1 [path_or_file2 [...]]\n\n -r - recursively search specified path(s)")
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.parse(*args)
|
17
|
+
fail if args.length == 0
|
18
|
+
|
19
|
+
recursive = args.include?('-r') ? !!args.delete('-r') : false
|
20
|
+
fail if args.any? {|a|a.start_with?('-')}
|
21
|
+
|
22
|
+
pathnames = []
|
23
|
+
if recursive
|
24
|
+
# recursively list all files under specified paths
|
25
|
+
require 'find'
|
26
|
+
args.each do |dir_or_file_path|
|
27
|
+
if FileTest.directory?(dir_or_file_path)
|
28
|
+
Find.find(dir_or_file_path) do |path|
|
29
|
+
if FileTest.directory?(path)
|
30
|
+
# ignore dot directories
|
31
|
+
if File.basename(path)[0] == ?.
|
32
|
+
Find.prune
|
33
|
+
else
|
34
|
+
next
|
35
|
+
end
|
36
|
+
else
|
37
|
+
pathnames << path
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
pathnames << path
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
args.each do |dir_or_file_path|
|
46
|
+
if FileTest.directory?(dir_or_file_path)
|
47
|
+
puts "Note: non-recursively listing directory '#{dir_or_file_path}'. For recursive search, use -r.\n\n"
|
48
|
+
pathnames += Dir.glob(dir_or_file_path).reject {|path| FileTest.directory?(path) || File.basename(path)[0] == ?.}
|
49
|
+
else
|
50
|
+
pathnames << dir_or_file_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if pathnames.length == 0
|
56
|
+
puts "No templates found."
|
57
|
+
return
|
58
|
+
end
|
59
|
+
|
60
|
+
pathnames.each do |pathname|
|
61
|
+
puts
|
62
|
+
puts '-' * pathname.length
|
63
|
+
puts pathname
|
64
|
+
puts '-' * pathname.length
|
65
|
+
puts
|
66
|
+
tree_path = []
|
67
|
+
File.open(pathname, 'r') do |file|
|
68
|
+
Angumine.parse(IO.read(file)).each {|s| puts s}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Angumine
|
4
|
+
class SaxParser < Nokogiri::XML::SAX::Document
|
5
|
+
|
6
|
+
attr_accessor :treepath, :name_to_branch, :mined_data
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
self.treepath ||= []
|
10
|
+
self.name_to_branch ||= {}
|
11
|
+
self.mined_data = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def am_clean_and_prefix_path(s)
|
15
|
+
return unless s
|
16
|
+
am_prefix_path(am_clean(s))
|
17
|
+
end
|
18
|
+
|
19
|
+
def am_clean(s)
|
20
|
+
s = s.join if s.is_a?(Array)
|
21
|
+
s = s.strip
|
22
|
+
end
|
23
|
+
|
24
|
+
def am_prefix_path(s)
|
25
|
+
return s if self.name_to_branch.length == 0
|
26
|
+
orig = s
|
27
|
+
|
28
|
+
ending = ''
|
29
|
+
non_var_name_index = s.index(/[\ \|]/)
|
30
|
+
s, ending = *[s[0,non_var_name_index], s[non_var_name_index,s.length]] if non_var_name_index
|
31
|
+
non_var_name_index = s.index('.')
|
32
|
+
s, rest_of_val = *[s[0,non_var_name_index], s[non_var_name_index,s.length]] if non_var_name_index
|
33
|
+
|
34
|
+
tree_branch_index = self.name_to_branch[s]
|
35
|
+
if tree_branch_index
|
36
|
+
"#{self.treepath[0..tree_branch_index].collect{|i|i[0]}.join('.')}#{rest_of_val}#{ending}"
|
37
|
+
else
|
38
|
+
orig
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_element name, attributes = []
|
43
|
+
if self.treepath.last
|
44
|
+
self.treepath.last[1] += 1 if self.treepath.last[1] > 0
|
45
|
+
end
|
46
|
+
Hash[attributes].each do |k,v|
|
47
|
+
next unless v
|
48
|
+
v = am_clean(v)
|
49
|
+
if k.start_with?('ng-') && k != 'ng-class' && v
|
50
|
+
if v.index(' in ')
|
51
|
+
loop_data = v.split(' in ')
|
52
|
+
arr = ["[#{loop_data[1]}]#{loop_data[0]}", 1]
|
53
|
+
self.name_to_branch[loop_data[0]] = self.treepath.length # which currently is the next index
|
54
|
+
self.treepath << arr
|
55
|
+
else
|
56
|
+
self.mined_data << "#{am_clean_and_prefix_path(v)}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def characters(s)
|
63
|
+
s.scan(/{{([^}]*)}}/).each {|v|self.mined_data << "#{am_clean_and_prefix_path(v)}"}
|
64
|
+
end
|
65
|
+
|
66
|
+
def end_element name
|
67
|
+
self.treepath.last[1] -= 1 if self.treepath.last && self.treepath.last[1] > 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angumine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gary S. Weaver
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
description: Angumine makes it easier to parse one or more templates (or parse recursively)
|
28
|
+
for references to data in ng-* attributes and within handlebars
|
29
|
+
email:
|
30
|
+
- garysweaver@gmail.com
|
31
|
+
executables:
|
32
|
+
- angumine
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/angumine/cli.rb
|
37
|
+
- lib/angumine/sax_parser.rb
|
38
|
+
- lib/angumine/version.rb
|
39
|
+
- lib/angumine.rb
|
40
|
+
- bin/angumine
|
41
|
+
- README.md
|
42
|
+
- LICENSE
|
43
|
+
homepage: https://github.com/garysweaver/angumine
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.0.6
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Mines AngularJS templates for data references
|
67
|
+
test_files: []
|