ngi 0.2.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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +164 -0
  6. data/Rakefile +2 -0
  7. data/bin/ngi +35 -0
  8. data/lib/config/angular_init.config.json +100 -0
  9. data/lib/config/backup.angular_init.config.json +72 -0
  10. data/lib/dep/json.rb +62 -0
  11. data/lib/dep/json/add/bigdecimal.rb +28 -0
  12. data/lib/dep/json/add/complex.rb +28 -0
  13. data/lib/dep/json/add/core.rb +11 -0
  14. data/lib/dep/json/add/date.rb +34 -0
  15. data/lib/dep/json/add/date_time.rb +50 -0
  16. data/lib/dep/json/add/exception.rb +31 -0
  17. data/lib/dep/json/add/ostruct.rb +31 -0
  18. data/lib/dep/json/add/range.rb +29 -0
  19. data/lib/dep/json/add/rational.rb +27 -0
  20. data/lib/dep/json/add/regexp.rb +30 -0
  21. data/lib/dep/json/add/struct.rb +30 -0
  22. data/lib/dep/json/add/symbol.rb +25 -0
  23. data/lib/dep/json/add/time.rb +38 -0
  24. data/lib/dep/json/common.rb +484 -0
  25. data/lib/dep/json/ext.rb +21 -0
  26. data/lib/dep/json/ext/.keep +0 -0
  27. data/lib/dep/json/generic_object.rb +70 -0
  28. data/lib/dep/json/pure.rb +21 -0
  29. data/lib/dep/json/pure/generator.rb +522 -0
  30. data/lib/dep/json/pure/parser.rb +359 -0
  31. data/lib/dep/json/version.rb +8 -0
  32. data/lib/ngi.rb +16 -0
  33. data/lib/ngi/configure.rb +165 -0
  34. data/lib/ngi/delegate.rb +24 -0
  35. data/lib/ngi/generator.rb +199 -0
  36. data/lib/ngi/utils/command_parser.rb +104 -0
  37. data/lib/ngi/utils/jser.rb +46 -0
  38. data/lib/ngi/utils/utils.rb +30 -0
  39. data/lib/ngi/version.rb +3 -0
  40. data/lib/templates/markup/html/default/index.html +11 -0
  41. data/lib/templates/script/coffee/default/basic.js +23 -0
  42. data/lib/templates/script/coffee/default/config.js +12 -0
  43. data/lib/templates/script/coffee/default/constant.js +7 -0
  44. data/lib/templates/script/coffee/default/module.js +7 -0
  45. data/lib/templates/script/es5/default/basic.js +29 -0
  46. data/lib/templates/script/es5/default/config.js +13 -0
  47. data/lib/templates/script/es5/default/constant.js +7 -0
  48. data/lib/templates/script/es5/default/module.js +7 -0
  49. data/ngi.gemspec +23 -0
  50. metadata +129 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 119801cbccb57371891100b9178b947823859d00
4
+ data.tar.gz: b129e85c5cc365c3e4fc2f2672fe1c0e40ca7506
5
+ SHA512:
6
+ metadata.gz: 255746a7d8b4dcf7c23f38cae6829adba8631860c9c8da90c48583ffd446889c541f362456d5237d3a2c63c1b51f7084832b37439610f39d907f9492bce3ac19
7
+ data.tar.gz: e6fd90484636fc1a66ec48dfe7082022c8f80795edf6538701af40fa68cbaebea07ae53a3b72723a0820ab01fa3409f54249056efeefbd554315bc90e7b4ad03
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ngi.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Joshua Beam
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,164 @@
1
+ # angular_init 0.2.0
2
+
3
+ <a href="http://joshbeam.github.io/angular_init">Website</a>
4
+
5
+ **What's different?**
6
+ - Install it as a gem (`gem install ngi`)
7
+ - You can now make an `index` boilerplate HTML page (`ngi index`)
8
+ - Use `ngi -h` to see all commands
9
+
10
+ ## In simple terms:
11
+
12
+ This tool (`ngi`) can make (for example) an AngularJS controller template file for you (`.js`), so that **whenever you want to make a new controller for your app, you don't have to type the same starting code over and over again** (by the way, this tool doesn't only create controllers. It does directives, filters... almost anything).
13
+
14
+ ## Why use `ngi` (and not something else)?
15
+
16
+ **`ngi` has one task, and one task only, which makes it lightweight and specialized**. Most AngularJS developers are probably using the command line already (Gulp, Bower, npm, Git, etc.), so why not use the command line to streamline your code-writing too?
17
+
18
+ Type less, write more AngularJS! Use `ngi`, the simple template generator.
19
+
20
+ ![Example](https://github.com/joshbeam/angular_init/blob/master/ngi_example.gif "Example")
21
+
22
+ # Table of Contents
23
+
24
+ - [Sample Usage][sample-usage]
25
+ - [Features][features]
26
+ - [Install in 1 step][install]
27
+ - [How to use it (docs)][commands]
28
+ - [FAQ][faq]
29
+ - [Technical Info][tech-info]
30
+
31
+ # Sample Usage
32
+
33
+ After you [do the 1-step installation][install] of `ngi` (the short-name for the shell script of `angular_init`), go to where your site is at (in this case, `~/MyAwesomeApp`). When you're in your site's project directory, just type `ngi <component>` to create a new JavaScript file for you!
34
+
35
+ ## Command line
36
+
37
+ ```shell
38
+ ~/MyAwesomeApp $ ngi controller # this will create a controller!
39
+
40
+ # you'll be prompted for some quick info
41
+ [?] New file name: myAwesome.controller.js
42
+ [?] Module name: myModule
43
+ [?] Controller name: MyAwesomeController
44
+ [?] Inject (already injected $scope): $route
45
+
46
+ # all done!
47
+ ```
48
+
49
+ ## Output (your new boilerplate code)
50
+
51
+ ```javascript
52
+ // ~/MyAwesomeApp/myAwesome.controller.js
53
+
54
+ ;(function(app) {
55
+
56
+ 'use strict';
57
+
58
+ app.controller('MyAwesomeController',MyAwesomeController);
59
+
60
+ MyAwesomeController.$inject = ['$route', '$scope'];
61
+
62
+ function MyAwesomeController($route, $scope) {
63
+
64
+ }
65
+
66
+ })(angular.module('myModule'));
67
+ ```
68
+
69
+ By the way, the output of this little tool is meant to follow [John Papa's AngularJS Style Guide][style-guide].
70
+
71
+ # Features
72
+
73
+ ## Current features
74
+
75
+ - Create a module, directive, controller, filter, run, config, "routes" config, constant, service, factory, or index HTML page by saying `ngi <component>`, where `<component>` is any of the above types (module, directive, etc.)
76
+ - Current languages that have default templates: CoffeeScript, ECMAScript5 (choose your language with `ngi --config (or -c)`)
77
+
78
+ ## Coming soon
79
+
80
+ - Add custom templates and languages
81
+
82
+ Feel free to fork the project or get <a href="http://frontendcollisionblog.com/about">in touch with Josh (me)</a> with any feature requests!
83
+
84
+ # Installation (in 1 step)
85
+
86
+ **Dependencies** [Ruby 2.1.0][ruby] and [RubyGems][rubygems] (optional [Bundler][bundler])
87
+
88
+ Add this line to your application's Gemfile:
89
+
90
+ gem 'ngi'
91
+
92
+ And then execute:
93
+
94
+ $ bundle
95
+
96
+ Or install it yourself as:
97
+
98
+ $ gem install ngi
99
+
100
+ # Commands
101
+
102
+ ```shell
103
+ ~/MyAwesomeApp $ ngi controller # => controller
104
+ ~/MyAwesomeApp $ ngi directive # => directive
105
+ ~/MyAwesomeApp $ ngi factory # => factory
106
+ ~/MyAwesomeApp $ ngi service # => service (same as factory)
107
+ ~/MyAwesomeApp $ ngi constant # => constant
108
+ ~/MyAwesomeApp $ ngi run # => a run block
109
+ ~/MyAwesomeApp $ ngi config # => a config block
110
+ ~/MyAwesomeApp $ ngi routes # => a config block with $routeProvider injected
111
+ ~/MyAwesomeApp $ ngi module # => module (you can inject dependencies too)
112
+ ~/MyAwesomeApp $ ngi filter # => filter
113
+
114
+ # or
115
+
116
+ ~/MyAwesomeApp $ ngi index # => an index page in HTML
117
+
118
+ # or
119
+
120
+ # use either --options or -o
121
+ ~/MyAwesomeApp $ ngi --options # => choose your language to use (CoffeeScript or ECMAScript5)
122
+ ```
123
+
124
+ # FAQ
125
+
126
+ **1. Can you explain why the module name is passed as the argument to the IIFE (in the default template)?**
127
+
128
+ - If you're using a JSHint plug-in, it will only say 'angular is not defined' in one place
129
+ - Eliminates the clutter of declaring something like `var app = angular.module('myModule')`
130
+ - Something like `angular.module('myModule')` cannot be minified, but the argument `app` can (only an issue if the full module getter happens multiple time)
131
+ - Streamlines the pattern across all of the templates
132
+
133
+ **2. Why are you using `$inject`?**
134
+
135
+ Check out [John Papa's Style Guide][style-guide].
136
+
137
+ **3. Why are you following the snake-case convention (`angular_init`) and not camelCase (`angularInit`) if this is a JavaScript project?**
138
+
139
+ The command line tool itself is written in <a href="https://www.ruby-lang.org/en/">Ruby</a>, and the <a href="https://github.com/bbatsov/ruby-style-guide#snake-case-files">convention</a> is to use snake-case for class file naming.
140
+
141
+ *For other questions and comments, check out this <a href="http://www.reddit.com/r/angularjs/comments/30ydha/command_line_tool_to_create_angularjs_controllers/">Reddit discussion</a> about `ngi` (feel free to post your own question too). Or, open a new issue on GitHub.*
142
+
143
+ # Technical Information
144
+
145
+ **Version** 0.2.0
146
+
147
+ **Language** Ruby
148
+
149
+ **Requirements** Only tested with `ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]`. Compatibility with previous versions of Ruby cannot be guaranteed.
150
+
151
+ <hr>
152
+
153
+ &copy; 2015 Joshua Beam (MIT License) &mdash; <a href="http://frontendcollisionblog.com">Front End Collision</a>
154
+
155
+ [install]: #installation-in-1-step
156
+ [sample-usage]: #sample-usage
157
+ [features]: #features
158
+ [commands]: #commands
159
+ [faq]: #faq
160
+ [tech-info]: #technical-information
161
+ [style-guide]: https://github.com/johnpapa/angular-styleguide
162
+ [rubygems]: https://rubygems.org/pages/download
163
+ [ruby]: https://www.ruby-lang.org/en/downloads/
164
+ [bundler]: http://bundler.io/
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ngi ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # angular_init (short-name: ngi)
4
+ # Copyright 2015 Joshua Beam
5
+ # github.com/joshbeam/angular_init
6
+ # MIT License
7
+
8
+ # Ngi is the main module (src/ruby/angular_init.rb)
9
+ require_relative '../lib/ngi'
10
+ require_relative '../lib/ngi/utils/utils'
11
+
12
+ class Parser
13
+ @@config = Ngi::Delegate::Configure.new.from_json
14
+ @@types = Ngi::UserInput.new(valid_inputs: @@config['global']['components'].collect{ |t| t['name'] })
15
+
16
+ def self.parse(args)
17
+ parser = Utils::CommandParser.new do |parser|
18
+ parser.name = "ngi"
19
+ parser.version = Ngi::VERSION
20
+ parser.banner << "\n(<command> can be one of the following)"
21
+
22
+ parser.on(@@types.valid_inputs, "Create a new component") do |command|
23
+ Ngi::Delegate::Generator.run(type: command, config: @@config)
24
+ end
25
+
26
+ parser.on(["-o","--options"], "Configure ngi") do
27
+ Ngi::Delegate::Configure.run()
28
+ end
29
+ end
30
+
31
+ parser.parse(args)
32
+ end
33
+ end
34
+
35
+ Parser.parse(ARGV)
@@ -0,0 +1,100 @@
1
+ {
2
+ "global": {
3
+ "configurable": {
4
+ "language": "language"
5
+ },
6
+ "menus": {
7
+ "options": "-options"
8
+ },
9
+ "languages": {
10
+ "script": [
11
+ "es5",
12
+ "coffee"
13
+ ],
14
+ "markup": [
15
+ "html"
16
+ ]
17
+ },
18
+ "language": {
19
+ "script": "es5",
20
+ "markup": "html"
21
+ },
22
+ "types": {
23
+ "script": "script",
24
+ "markup": "markup"
25
+ },
26
+ "components": [
27
+ {
28
+ "name": "directive",
29
+ "type": "script",
30
+ "using": "default",
31
+ "template": "basic.js"
32
+ },
33
+ {
34
+ "name": "controller",
35
+ "type": "script",
36
+ "using": "default",
37
+ "template": "basic.js"
38
+ },
39
+ {
40
+ "name": "factory",
41
+ "type": "script",
42
+ "using": "default",
43
+ "template": "basic.js"
44
+ },
45
+ {
46
+ "name": "service",
47
+ "type": "script",
48
+ "using": "default",
49
+ "template": "basic.js"
50
+ },
51
+ {
52
+ "name": "config",
53
+ "type": "script",
54
+ "using": "default",
55
+ "template": "config.js"
56
+ },
57
+ {
58
+ "name": "run",
59
+ "type": "script",
60
+ "using": "default",
61
+ "template": "config.js"
62
+ },
63
+ {
64
+ "name": "routes",
65
+ "type": "script",
66
+ "using": "default",
67
+ "template": "config.js"
68
+ },
69
+ {
70
+ "name": "filter",
71
+ "type": "script",
72
+ "using": "default",
73
+ "template": "basic.js"
74
+ },
75
+ {
76
+ "name": "module",
77
+ "type": "script",
78
+ "using": "default",
79
+ "template": "module.js"
80
+ },
81
+ {
82
+ "name": "constant",
83
+ "type": "script",
84
+ "using": "default",
85
+ "template": "constant.js"
86
+ },
87
+ {
88
+ "name": "index",
89
+ "type": "markup",
90
+ "using": "default",
91
+ "template": "index.html"
92
+ }
93
+ ],
94
+ "aliases": {
95
+ "config": [
96
+ "routes"
97
+ ]
98
+ }
99
+ }
100
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "global": {
3
+ "configurable": {
4
+ "language": "language"
5
+ },
6
+ "menus": {
7
+ "options": "-options"
8
+ },
9
+ "languages": [
10
+ "es5",
11
+ "coffee"
12
+ ],
13
+ "language": "es5",
14
+ "types": [
15
+ {
16
+ "name": "directive",
17
+ "source": "default",
18
+ "template": "basic.js"
19
+ },
20
+ {
21
+ "name": "controller",
22
+ "source": "default",
23
+ "template": "basic.js"
24
+ },
25
+ {
26
+ "name": "factory",
27
+ "source": "default",
28
+ "template": "basic.js"
29
+ },
30
+ {
31
+ "name": "service",
32
+ "source": "default",
33
+ "template": "basic.js"
34
+ },
35
+ {
36
+ "name": "config",
37
+ "source": "default",
38
+ "template": "config.js"
39
+ },
40
+ {
41
+ "name": "run",
42
+ "source": "default",
43
+ "template": "config.js"
44
+ },
45
+ {
46
+ "name": "routes",
47
+ "source": "default",
48
+ "template": "config.js"
49
+ },
50
+ {
51
+ "name": "filter",
52
+ "source": "default",
53
+ "template": "basic.js"
54
+ },
55
+ {
56
+ "name": "module",
57
+ "source": "default",
58
+ "template": "module.js"
59
+ },
60
+ {
61
+ "name": "constant",
62
+ "source": "default",
63
+ "template": "constant.js"
64
+ }
65
+ ],
66
+ "aliases": {
67
+ "config": [
68
+ "routes"
69
+ ]
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,62 @@
1
+ require 'json/common'
2
+
3
+ ##
4
+ # = JavaScript Object Notation (JSON)
5
+ #
6
+ # JSON is a lightweight data-interchange format. It is easy for us
7
+ # humans to read and write. Plus, equally simple for machines to generate or parse.
8
+ # JSON is completely language agnostic, making it the ideal interchange format.
9
+ #
10
+ # Built on two universally available structures:
11
+ # 1. A collection of name/value pairs. Often referred to as an _object_, hash table, record, struct, keyed list, or associative array.
12
+ # 2. An ordered list of values. More commonly called an _array_, vector, sequence or list.
13
+ #
14
+ # To read more about JSON visit: http://json.org
15
+ #
16
+ # == Parsing JSON
17
+ #
18
+ # To parse a JSON string received by another application or generated within
19
+ # your existing application:
20
+ #
21
+ # require 'json'
22
+ #
23
+ # my_hash = JSON.parse('{"hello": "goodbye"}')
24
+ # puts my_hash["hello"] => "goodbye"
25
+ #
26
+ # Notice the extra quotes <tt>''</tt> around the hash notation. Ruby expects
27
+ # the argument to be a string and can't convert objects like a hash or array.
28
+ #
29
+ # Ruby converts your string into a hash
30
+ #
31
+ # == Generating JSON
32
+ #
33
+ # Creating a JSON string for communication or serialization is
34
+ # just as simple.
35
+ #
36
+ # require 'json'
37
+ #
38
+ # my_hash = {:hello => "goodbye"}
39
+ # puts JSON.generate(my_hash) => "{\"hello\":\"goodbye\"}"
40
+ #
41
+ # Or an alternative way:
42
+ #
43
+ # require 'json'
44
+ # puts {:hello => "goodbye"}.to_json => "{\"hello\":\"goodbye\"}"
45
+ #
46
+ # <tt>JSON.generate</tt> only allows objects or arrays to be converted
47
+ # to JSON syntax. <tt>to_json</tt>, however, accepts many Ruby classes
48
+ # even though it acts only as a method for serialization:
49
+ #
50
+ # require 'json'
51
+ #
52
+ # 1.to_json => "1"
53
+ #
54
+ module JSON
55
+ require 'json/version'
56
+
57
+ begin
58
+ require 'json/ext'
59
+ rescue LoadError
60
+ require 'json/pure'
61
+ end
62
+ end