rugular 0.2.9 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e91bc2b3ee5ce6b5d97a02aff336cf6369a81f9
4
- data.tar.gz: 1a571bd4c7dd643c5ffec59d1c8cdef59a02847f
3
+ metadata.gz: 9895febe3588522340a989787667333c945a16df
4
+ data.tar.gz: 6d883bbad76d22d0771a96cd3b1050e986899275
5
5
  SHA512:
6
- metadata.gz: 7c30c586cffa195aa6ea9f6763fb166ff3ad06b6e6d18562cdb99a74f981cf55e2485e3269c53f3496d7810db2cb1584865d7c5ae4a28b432b635d3653318be6
7
- data.tar.gz: b96d44a9cc9ad3fbf23f5f8ec172e56757c4d843e0f072b96b6df740b7264ba62f11d517e9f30d193639821ff926078bae5a15781a6383b4765c47024b971845
6
+ metadata.gz: 148ce01ce2a52f86e052d2ddba88a9a7e2242022a3e9b9416091e0d790c2c8eba47c47d7785b649d64a0bfc0a86270309feddc82af9700761bac6125bb3b82b2
7
+ data.tar.gz: dfc3206be59c680da3de8cb714ff5401973ec4dfd8b765b4f6b7df96e7ee99eedac2de52b9de6c6a89942a3be2999b435b28546b17f90a34432463afe2bb37cc
data/README.md CHANGED
@@ -3,46 +3,36 @@ Status](https://circleci.com/gh/currica/rugular.svg?style=shield&circle-token=:c
3
3
 
4
4
  # Rugular
5
5
 
6
- Rugular is a ruby scaffolding framework to build AngularJS apps. It builds a
7
- minified and compressed version of a front-end into the ``./dist`` folder that
8
- can be served as a standalone AngularJS app. The goal of this framework is to
9
- create applications written with [best AngularJS
10
- practices](https://github.com/johnpapa/angularjs-styleguide) using
11
- CoffeeScript, Haml and Sass.
6
+ Rugular is a framework to build AngularJS apps; the goal is to
7
+ provide a rails-like interface to constructing a UI with Sass, Haml, and
8
+ Coffeescript, and generators to create template files.
12
9
 
13
10
  ## Installation
14
11
 
15
- Add this line to your application's Gemfile:
16
-
17
- ```ruby
18
- gem 'rugular'
12
+ ```bash
13
+ gem install rugular
19
14
  ```
20
15
 
21
- And then execute:
22
-
23
- $ bundle
24
-
25
- Or install it yourself as:
26
-
27
- $ gem install rugular
28
-
29
16
  ## Start a new project
30
17
 
31
18
  ```bash
32
19
  rugular new <project_name>
33
20
  ```
34
21
 
35
- This will create the initial project template that follows [Google's Best
36
- Practices for an Angular App
37
- Structure](https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub).
22
+ A new Rugular project contains the following folders:
23
+
38
24
  <pre>
25
+ ├── .application.sass
26
+ ├── .gitignore/
27
+ ├── .tmp/
39
28
  ├── bower_components/
40
29
  ├── bower.json
41
30
  ├── Gemfile
31
+ ├── node_modules/
42
32
  ├── package.json
43
33
  ├── src/
44
- │ ├── application.sass (manifest file)
45
34
  │ ├── app/
35
+ │ │ ├── _app.sass
46
36
  │ │ ├── app.module.coffee
47
37
  │ │ ├── app.config.coffee
48
38
  │ │ ├── app.controller.coffee
@@ -50,101 +40,128 @@ Structure](https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcu
50
40
  │ │ ├── app.routes.coffee
51
41
  │ │ ├── index.haml
52
42
  │ ├── components/
53
- │ ├── 404.html
54
- │ ├── 500.html
55
43
  │ ├── favico.ico
44
+ │ ├── fonts/
45
+ │ ├── images/
46
+ ├── vendor/
56
47
  </pre>
57
48
 
58
- ## Development Server
49
+ | Folder/File Name | Description |
50
+ | --- | --- |
51
+ | .application.sass | A manifest sass file for development purposes |
52
+ | .gitignore | Many of the files and folders here are not needed for source control, when deploying an application, please use the ``rugular build`` command described below |
53
+ | .tmp | A temporary folder used for storing compiled Haml, Sass, and Coffeescript files. |
54
+ | bower_components | A folder used by bower to install packages. |
55
+ | bower.json | A list of packages to be installed by bower |
56
+ | Gemfile | A way to install the ``rugular`` gem locally. This is not needed if you install ``rugular`` globally |
57
+ | node_modules | A folder used by npm to install packages. |
58
+ | package.json | A list of packages to be installed by npm |
59
+ | src | A folder containing the source code unique to a rugular application. Rugular apps are written in Haml, Coffeescript and Sass and designed to follow [Google's Best Practices for an Angular App Structure](https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub). |
60
+ | src/fonts and src/images | Folders to place fonts and images respectively, in a rugular application they are referenced by their relative filename, e.g. ``src/images/logo.png`` can be linked as ``<img src='images/logo.png'></img>``
61
+ | vendor | 3rd-party javascript, coffeescript, css, and sass files that do not come with bower management. All of these files are included before any code in src. |
59
62
 
60
- Rugular includes a built in server that will interpret Coffeescript/Haml/Sass
61
- and run a server on ``localhost:8080``. To run the server, type:
63
+ ### Rugular Generators
62
64
 
63
- ```bash
64
- bundle exec rugular server
65
- ```
65
+ Rugular generators assist with developing apps by creating template files in
66
+ the src directory. These are influenced by [John Papa's AngularJS Style
67
+ Guide](https://github.com/johnpapa/angularjs-styleguide).
66
68
 
67
- You must have [http-server](https://github.com/nodeapps/http-server) installed.
69
+ Each command will create a folder in the ``src/app`` directory that will
70
+ contain the template files and new angular module file if one does not already
71
+ exist. It will also register the angular module, by inserting its declaration
72
+ in the appropriate spot in your application.
68
73
 
69
- ## Running the tests
74
+ Each command can also contain nesting instructions when you find it appropriate
75
+ to nest angular modules. An example of nesting is given below.
76
+
77
+ #### Create a Route
78
+
79
+ A route refers to the files necessary to generate a URL route in an angular
80
+ application. Rugular utilizes [Angular UI
81
+ Router](https://github.com/angular-ui/ui-router) in its template files.
70
82
 
71
- ### Unit Tests
83
+ ```bash
84
+ rugular generate route <route_name>
85
+ ```
72
86
 
73
- Unit tests are included in the development server. To run these tests just once
74
- (perhaps for CI) run:
87
+ For example, ``rugular generate route dashboard`` generates the following files:
75
88
 
76
89
  ```
77
- karma start karma.conf.js --single-run
90
+ src/app/_dashboard.sass
91
+ src/app/dashboard.controller.coffee
92
+ src/app/dashboard.haml
93
+ src/app/dashboard.module.coffee
94
+ src/app/dashboard.routes.coffee
78
95
  ```
79
96
 
80
- ### End to End tests
97
+ In your browser, the default ui can be seen by visiting ``/dashboard``
81
98
 
82
- End to end tests with protractor can be run with:
99
+ #### Creating a nested route:
83
100
 
84
101
  ```bash
85
- protractor
102
+ rugular generate route admin:dashboard
86
103
  ```
87
104
 
88
- Please make sure you have mocha installed globally!
105
+ generates:
89
106
 
90
- ### Rugular Generators
107
+ ```
108
+ src/app/admin/_dashboard.sass
109
+ src/app/admin/dashboard.controller.coffee
110
+ src/app/admin/dashboard.haml
111
+ src/app/admin/dashboard.module.coffee
112
+ src/app/admin/dashboard.routes.coffee
113
+ ```
91
114
 
92
- #### Create a Route
115
+ with a new route at ``/admin/dashboard``
93
116
 
94
- A route creates a angular route, controller, and view in the app folder.
117
+ #### Create a Directive
118
+
119
+ A [directive](https://docs.angularjs.org/guide/directive) refers to an
120
+ abstracted piece of DOM.
95
121
 
96
122
  ```bash
97
- rugular generate route <route_name>
123
+ rugular generate directive <directive_name>
98
124
  ```
99
125
 
100
- This command will create a folder in the ``src/app`` directory that will
101
- contain a controller and service namespaced with a new module of the route
102
- name if one dos not already exist. It will also register the new module in the
103
- ``app.module.js`` file.
104
-
105
- Routes can be nested in another folder representing a module. For example, to
106
- nest a route inside a pre-existing 'test' module, execute:
126
+ #### Create a Factory (TODO)
107
127
 
108
128
  ```bash
109
- rugular generate route test:<route_name>
129
+ rugular generate factory <factory_name>
110
130
  ```
111
131
 
112
- #### Create a Directive
132
+ #### Create a Filter (TODO)
113
133
 
114
134
  ```bash
115
- rugular generate directive <directive_name>
135
+ rugular generate filter <factory_name>
116
136
  ```
117
137
 
118
- This command will create a directive and controller namespaced with a new
119
- module of the feature name if one does not already exist. It will also register
120
- the new module in the ``app.module.js`` file.
138
+ ### Creating a component
121
139
 
122
- Directives can be nested in another folder representing a module like routes.
123
- For example, to nest a directive inside a pre-existing 'test' module, execute:
140
+ A component refers to shareable, abstracted angular modules, that are not
141
+ particular to your application. For instance, if you are developing a suite of
142
+ separate applications, a common navigation bar may qualify as a component. To
143
+ create a component, simply run any generator command with the ``-c`` option and
144
+ the service will be created in the ``src/components`` folder.
124
145
 
125
- ```bash
126
- rugular generate directive test:<directive_name>
127
- ```
146
+ ## Development Server
128
147
 
129
- #### Create a Factory (TODO)
148
+ Rugular includes a built in server that will interpret Coffeescript/Haml/Sass
149
+ and run a server on ``localhost:5000``. To run the server, type:
130
150
 
131
151
  ```bash
132
- rugular generate factory <factory_name>
152
+ bundle exec rugular server
133
153
  ```
134
154
 
135
- This command will create contain a factory namespaced with a new module of the
136
- feature name if one does not already exist. It will also register the new
137
- module in the ``app.module.js`` file.
155
+ ## Running the tests
138
156
 
139
- ### Creating a component
157
+ ### During development
140
158
 
141
- A component refers to shareable, abstracted angular modules. To create a
142
- component, simply run any generator command with the ``-c`` option and the
143
- service will be created in the ``src/components`` folder.
159
+ ``rugular server`` runs the tests with karma. Karma watches the files in the
160
+ ``src`` directory and runs the tests on each save.
144
161
 
145
- ## Running the Test Suite
162
+ ### Running the tests once
146
163
 
147
- To run the test suite just once (such as in a continuous environment) execute:
164
+ To run these tests just once (perhaps for CI) run:
148
165
 
149
166
  ```bash
150
167
  rugular ci
@@ -152,8 +169,19 @@ rugular ci
152
169
 
153
170
  ## Building the app
154
171
 
155
- Rugular builds a minified, compressed version of your app in the ``/dist``
156
- folder. This is done for you by the ``rugular server`` command.
172
+ To build a minified version of your app in the ``/dist`` folder execute:
173
+
174
+ ```bash
175
+ rugular build
176
+ ```
177
+
178
+ This will create the following files:
179
+
180
+ * index.html
181
+ * application.css (a minified version of the sass files in the src folder)
182
+ * vendor.css (a minified version of bower_component and vendor files)
183
+ * application.js (a minified version of the coffee files in the src folder)
184
+ * vendor.js (a minified version of bower_component and vendor files)
157
185
 
158
186
  ## Contributing
159
187
 
@@ -1,4 +1,8 @@
1
1
  Dir.glob("#{__dir__}/helpers/**/*.rb").each {|file| require file}
2
+ require 'uglifier'
3
+ require 'coffee_script'
4
+ require 'sass'
5
+ require 'haml'
2
6
 
3
7
  module Rugular
4
8
  class Build < Thor::Group
@@ -8,20 +12,97 @@ module Rugular
8
12
 
9
13
  Rugular::AppChecker.check_rugular!(self.name, new.destination_root)
10
14
 
11
- # TODO: build from the ./.tmp folder
12
- def compile_coffeescript
13
- puts CoffeeScript.compile File.read("app.coffee")
15
+ def create_dist_folder
16
+ FileUtils.mkdir_p('./dist') unless File.directory? './dist'
14
17
  end
15
18
 
16
- def uglify_css
17
- puts Uglifier.compile(CoffeeScript.compile File.read("app.coffee"))
19
+ def write_dist_index_html_file
20
+ File.open('dist/index.html', 'w') do |file|
21
+ file.write ::Haml::Engine.new(File.read('src/index.haml')).render
22
+ end
18
23
  end
19
24
 
20
- def interpret_sass
21
- template = File.load('stylesheets/sassy.sass')
22
- sass_engine = Sass::Engine.new(template)
23
- output = sass_engine.render
24
- puts output
25
+ def compile_bower_javascript
26
+ File.open('dist/vendor.js', 'w') do |file|
27
+ file.write(Uglifier.compile(bower_and_vendor_javascript))
28
+ end
29
+ end
30
+
31
+ def compile_bower_stylesheets
32
+ File.open('dist/vendor.css', 'w') do |file|
33
+ file.write bower_css
34
+ end
35
+ end
36
+
37
+ def create_application_js_file
38
+ File.open('dist/application.js', 'w') do |file|
39
+ file.write(
40
+ Uglifier.compile(
41
+ javascript_files.map do |file|
42
+ text = File.read(file).gsub('templateUrl', 'template')
43
+ CoffeeScript.compile(text)
44
+ end.join
45
+ )
46
+ )
47
+ end
48
+ end
49
+
50
+ def inline_template_url_files
51
+ (Dir.glob("**/*.haml") - ["src/index.haml"]).each do |haml_file|
52
+ haml_html = ::Haml::Engine.new(File.read(haml_file), {}).render
53
+ html = haml_html.tr("\n", '').gsub("'", "\'").gsub('"', '\"')
54
+ html_filename = haml_file.gsub('src/', '').gsub('haml', 'html')
55
+ IO.write('dist/application.js', File.open('dist/application.js') do |f|
56
+ f.read.gsub(html_filename, html)
57
+ end)
58
+ end
59
+ end
60
+
61
+ def create_application_css_file
62
+ `sass .application.sass dist/application.css -r sass-globbing`
63
+ end
64
+
65
+ private
66
+
67
+ def bower_and_vendor_javascript
68
+ bower_javascript + vendor_javascript
69
+ end
70
+
71
+ def bower_javascript
72
+ bower_yaml.fetch('bower_components').fetch('js').map do |filename|
73
+ File.read('bower_components/' + filename)
74
+ end.join
75
+ end
76
+
77
+ def vendor_javascript
78
+ bower_yaml.fetch('vendor').fetch('coffee').map do |filename|
79
+ CoffeeScript.compile(File.read('vendor/' + filename))
80
+ end.join
81
+ end
82
+
83
+ def javascript_files
84
+ Dir.glob("src/**/*.module.coffee").sort(&reverse_nested) +
85
+ Dir.glob("src/**/*.routes.coffee").sort(&reverse_nested) +
86
+ Dir.glob("src/**/*.factory.coffee").sort(&reverse_nested) +
87
+ Dir.glob("src/**/*.controller.coffee").sort(&reverse_nested) +
88
+ Dir.glob("src/**/*.directive.coffee").sort(&reverse_nested)
89
+ end
90
+
91
+ def reverse_nested
92
+ lambda do |x, y|
93
+ x.scan('/').length <=> y.scan('/').length
94
+ end
95
+ end
96
+
97
+ def bower_css
98
+ bower_yaml.fetch('bower_components').fetch('css').map do |filename|
99
+ File.read('bower_components/' + filename)
100
+ end.join
101
+ end
102
+
103
+
104
+ def bower_yaml
105
+ YAML.load(File.read('src/vendor_and_bower_components.yaml'))
25
106
  end
26
107
  end
27
108
  end
@@ -1,5 +1,5 @@
1
- web: http-server dist
1
+ web: http-server .tmp
2
2
  guard: bundle exec guard --guardfile=$(bundle show rugular)/lib/rugular/tasks/server/Guardfile
3
- sass: sass --watch --load-path src src/application.sass:dist/application.css
3
+ sass: sass --watch .application.sass:.tmp/application.css -r sass-globbing
4
4
  karma: ./node_modules/karma/bin/karma start karma.conf
5
5
 
@@ -1,7 +1,9 @@
1
- require 'haml'
2
- require 'coffee_script'
3
- require 'uglifier'
4
1
  require 'guard'
2
+ require_relative 'rugular_haml'
3
+ require_relative 'rugular_coffee'
4
+ require_relative 'rugular_vendor_and_bower_components'
5
+ require_relative 'rugular_index_html'
6
+ require_relative 'rugular_assets'
5
7
 
6
8
  module Guard
7
9
  class Rugular < Plugin
@@ -10,126 +12,68 @@ module Guard
10
12
  super(opts)
11
13
  end
12
14
 
13
- def start; true end
15
+ def start
16
+ ::RugularHaml.compile('src/index.haml')
17
+ end
18
+
14
19
  def stop; true end
15
20
  def reload; true end
16
21
 
17
22
  def run_all
18
- run_on_changes('src/app/app.coffee')
23
+ run_on_changes(Dir.glob("src/**/*"))
19
24
  end
20
25
 
21
26
  def run_on_changes(paths)
22
- paths.each do |file|
23
- ::Guard::UI.info "Guard received save event for #{file}"
24
-
25
- case file.split('.').last
26
- when 'haml' then message = compile_haml(file)
27
- when 'coffee' then message = compile_coffee(file)
28
- when 'yaml' then message = compile_yaml
29
- end
27
+ [*paths].each do |file|
28
+ message = case File.extname(file)
29
+ when '.coffee' then ::RugularCoffee.compile(file)
30
+ when '.haml' then ::RugularHaml.compile(file)
31
+ when '.yaml' then ::RugularVendorAndBowerComponents.compile
32
+ when '.png' then ::RugularAssets.copy_image(file)
33
+ when '.jpg' then ::RugularAssets.copy_image(file)
34
+ when '.ttf' then ::RugularAssets.copy_font(file)
35
+ when '.woff' then ::RugularAssets.copy_font(file)
36
+ else next 'Rugular does not know how to handle this file'
37
+ end
38
+
39
+ ::RugularIndexHtml.update_javascript_script_tags
30
40
 
31
41
  ::Guard::UI.info message
32
42
  end
33
- end
34
-
35
- def run_on_removals(paths)
36
- run_on_changes(paths)
37
- end
38
-
39
- private
40
-
41
- def compile_haml(file)
42
- html = ::Haml::Engine.new(File.read(file)).render
43
-
44
- if file.include? 'src/index.haml'
45
- File.open('dist/index.html', 'w') do |file|
46
- file.write html
47
- end
48
- else
49
- compile_coffee('src/app/app.module.coffee')
50
- end
51
-
52
- message = "Successfully compiled #{file} to html!\n"
53
43
  rescue StandardError => error
54
44
  handle_error_in_guard(error)
55
45
  end
56
46
 
57
- def compile_coffee(file)
58
- CoffeeScript.compile(file)
59
-
60
- File.open('dist/application.js', 'w') do |file|
61
- file.write(
62
- javascript_files.map do |file|
63
- text = File.read(file).gsub('templateUrl', 'template')
64
- CoffeeScript.compile(text)
65
- end.join
66
- )
67
- end
68
-
69
- # Inline templates into javascript
70
- (Dir.glob("**/*.haml") - ["src/index.haml"]).each do |haml_file|
71
- haml_html = ::Haml::Engine.new(File.read(haml_file), {}).render
72
- html = haml_html.tr("\n", '').gsub('"', '\"')
73
- html_filename = haml_file.gsub('src/', '').gsub('haml', 'html')
74
- IO.write('dist/application.js', File.open('dist/application.js') do |f|
75
- f.read.gsub(html_filename, html)
76
- end)
77
- end
78
-
79
- message = "Successfully compiled #{file} to js!\n"
80
- rescue StandardError => error
81
- handle_error_in_guard(error)
82
- end
47
+ def run_on_removals(paths)
48
+ [*paths].each do |file|
49
+ ::Guard::UI.info "Guard received delete event for #{file}"
50
+
51
+ message = case File.extname(file)
52
+ when '.coffee' then ::RugularCoffee.delete(file)
53
+ when '.haml' then ::RugularHaml.delete(file)
54
+ when '.png' then ::RugularAssets.delete_image(file)
55
+ when '.jpg' then ::RugularAssets.delete_image(file)
56
+ when '.ttf' then ::RugularAssets.delete_font(file)
57
+ when '.woff' then ::RugularAssets.delete_font(file)
58
+ when '.yaml'
59
+ then fail 'what are you doing? trying to break rugular?!'
60
+ else next 'Rugular does not know how to handle this file'
61
+ end
62
+
63
+ ::RugularIndexHtml.update_javascript_script_tags
83
64
 
84
- def compile_yaml
85
- File.open("dist/bower_components.css", 'w') do |file|
86
- file.write bower_css
87
- end
88
- File.open("dist/bower_components.js", 'w') do |file|
89
- file.write Uglifier.compile(bower_javascript)
65
+ ::Guard::UI.info message
90
66
  end
91
-
92
- message = 'Successfully created bower_component dist files'
93
67
  rescue StandardError => error
94
68
  handle_error_in_guard(error)
95
69
  end
96
70
 
97
- def bower_css
98
- bower_yaml.fetch('css').map do |filename|
99
- File.read('bower_components/' + filename)
100
- end.join
101
- end
102
-
103
- def bower_javascript
104
- bower_yaml.fetch('js').map do |filename|
105
- File.read('bower_components/' + filename)
106
- end.join
107
- end
108
-
109
- def bower_yaml
110
- YAML.load(File.read('src/bower_components.yaml'))
111
- end
71
+ private
112
72
 
113
73
  def handle_error_in_guard(error)
114
- message = "#{error.message}"
115
- ::Guard::UI.error message
74
+ ::Guard::UI.error error.message
116
75
  throw :task_has_failed
117
76
  end
118
-
119
- def javascript_files
120
- Dir.glob("**/*.module.coffee").sort(&reverse_nested) +
121
- Dir.glob("**/*.routes.coffee").sort(&reverse_nested) +
122
- Dir.glob("**/*.factory.coffee").sort(&reverse_nested) +
123
- Dir.glob("**/*.controller.coffee").sort(&reverse_nested) +
124
- Dir.glob("**/*.directive.coffee").sort(&reverse_nested)
125
- end
126
-
127
- def reverse_nested
128
- lambda do |x, y|
129
- x.scan('/').length <=> y.scan('/').length
130
- end
131
- end
132
-
133
77
  end
134
78
  end
135
79
 
@@ -0,0 +1,19 @@
1
+ class RugularAssets
2
+ def self.copy_image(file)
3
+ FileUtils.mkdir('.tmp/images') unless File.directory? '.tmp/images'
4
+ FileUtils.cp(file, ".tmp/images/#{File.basename(file)}")
5
+ end
6
+
7
+ def self.copy_font(file)
8
+ FileUtils.mkdir('.tmp/fonts') unless File.directory? '.tmp/fonts'
9
+ FileUtils.cp(file, ".tmp/fonts/#{File.basename(file)}")
10
+ end
11
+
12
+ def self.delete_image(file)
13
+ FileUtils.rm(".tmp/images/#{File.basename(file)}")
14
+ end
15
+
16
+ def self.delete_font(file)
17
+ FileUtils.rm(".tmp/fonts/#{File.basename(file)}")
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require 'coffee_script'
2
+
3
+ class RugularCoffee
4
+ def self.compile(coffee_file)
5
+ new(coffee_file).compile
6
+ end
7
+
8
+ def self.delete(coffee_file)
9
+ new(coffee_file).delete
10
+ end
11
+
12
+ def initialize(coffee_file)
13
+ @coffee_file = coffee_file
14
+ end
15
+
16
+ def compile
17
+ write_tmp_file
18
+
19
+ "Successfully compiled #{coffee_file} to html!\n"
20
+ end
21
+
22
+ def delete
23
+ FileUtils.rm(tmp_file)
24
+
25
+ "Sucessfully removed #{tmp_file}\n"
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :coffee_file
31
+
32
+ def javascript
33
+ @_javascript ||= CoffeeScript.compile(File.open(coffee_file))
34
+ end
35
+
36
+ def tmp_file
37
+ coffee_file.gsub('src', '.tmp').gsub('coffee', 'js')
38
+ end
39
+
40
+ def write_tmp_file
41
+ create_tmp_folder
42
+
43
+ File.open(tmp_file, 'w', &write_javascript)
44
+ end
45
+
46
+ def create_tmp_folder
47
+ dirname = File.dirname(tmp_file)
48
+
49
+ FileUtils.mkdir_p(dirname) unless File.directory? dirname
50
+ end
51
+
52
+ def write_javascript
53
+ ->(file) { file.write javascript }
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require 'haml'
2
+
3
+ class RugularHaml
4
+ def self.compile(haml_file)
5
+ new(haml_file).compile
6
+ end
7
+
8
+ def self.delete(haml_file)
9
+ new(haml_file).delete
10
+ end
11
+
12
+ def initialize(haml_file)
13
+ @haml_file = haml_file
14
+ end
15
+
16
+ def compile
17
+ write_tmp_file
18
+
19
+ "Successfully compiled #{haml_file} to html!\n"
20
+ end
21
+
22
+ def delete
23
+ FileUtils.rm(tmp_file)
24
+
25
+ "Sucessfully removed #{tmp_file}\n"
26
+ end
27
+
28
+ private
29
+
30
+ def html
31
+ @_html ||= ::Haml::Engine.new(File.read(haml_file)).render
32
+ end
33
+
34
+ attr_reader :haml_file
35
+
36
+ def tmp_file
37
+ haml_file.gsub('src', '.tmp').gsub('haml', 'html')
38
+ end
39
+
40
+ def write_tmp_file
41
+ create_tmp_folder
42
+
43
+ File.open(tmp_file, 'w', &write_html)
44
+ end
45
+
46
+ def write_html
47
+ ->(file) { file.write html }
48
+ end
49
+
50
+ def create_tmp_folder
51
+ dirname = File.dirname(tmp_file)
52
+
53
+ FileUtils.mkdir_p(dirname) unless File.directory? dirname
54
+ end
55
+ end
@@ -0,0 +1,66 @@
1
+ require 'nokogiri'
2
+
3
+ class RugularIndexHtml
4
+ def self.update_javascript_script_tags
5
+ new.update_javascript_script_tags
6
+ end
7
+
8
+ def initialize; end
9
+
10
+ def update_javascript_script_tags
11
+ remove_application_javascript_tags
12
+
13
+ add_javascript_files
14
+
15
+ File.open('.tmp/index.html', 'w') { |file| file.write application_html }
16
+ end
17
+
18
+ private
19
+
20
+ def remove_application_javascript_tags
21
+ application_javascript_node.children.remove
22
+ end
23
+
24
+ def add_javascript_files
25
+ application_javascript_node.children = javascript_file_script_tags
26
+ end
27
+
28
+ def javascript_file_script_tags
29
+ Nokogiri::XML::NodeSet.new(
30
+ application_html,
31
+ javascript_files.map(&convert_to_script_tag)
32
+ )
33
+ end
34
+
35
+ def javascript_files
36
+ Dir.glob("src/**/*.module.coffee").sort(&reverse_nested) +
37
+ Dir.glob("src/**/*.routes.coffee").sort(&reverse_nested) +
38
+ Dir.glob("src/**/*.factory.coffee").sort(&reverse_nested) +
39
+ Dir.glob("src/**/*.controller.coffee").sort(&reverse_nested) +
40
+ Dir.glob("src/**/*.directive.coffee").sort(&reverse_nested)
41
+ end
42
+
43
+ def reverse_nested
44
+ lambda do |x, y|
45
+ x.scan('/').length <=> y.scan('/').length
46
+ end
47
+ end
48
+
49
+ def convert_to_script_tag
50
+ lambda do |javascript_file|
51
+ tmp_filename = javascript_file.gsub('src', '').gsub('coffee', 'js')
52
+
53
+ Nokogiri::XML::Node.new 'script', application_html do |node|
54
+ node['src'] = tmp_filename
55
+ end
56
+ end
57
+ end
58
+
59
+ def application_html
60
+ @_html ||= Nokogiri::HTML(File.read('.tmp/index.html'))
61
+ end
62
+
63
+ def application_javascript_node
64
+ application_html.at_css('.application_javascript')
65
+ end
66
+ end
@@ -0,0 +1,51 @@
1
+ require 'uglifier'
2
+ require 'coffee_script'
3
+
4
+ class RugularVendorAndBowerComponents
5
+ def self.compile
6
+ new.compile
7
+ end
8
+
9
+ def initialize; end
10
+
11
+ def compile
12
+ File.open('.tmp/vendor.css', 'w') do |file|
13
+ file.write bower_css
14
+ end
15
+ File.open('.tmp/vendor.js', 'w') do |file|
16
+ file.write(Uglifier.compile(bower_and_vendor_javascript))
17
+ end
18
+
19
+ message = 'Successfully created vendor asset files'
20
+ rescue StandardError => error
21
+ handle_error_in_guard(error)
22
+ end
23
+
24
+ private
25
+
26
+ def bower_and_vendor_javascript
27
+ bower_javascript + vendor_javascript
28
+ end
29
+
30
+ def bower_css
31
+ bower_yaml.fetch('bower_components').fetch('css').map do |filename|
32
+ File.read('bower_components/' + filename)
33
+ end.join
34
+ end
35
+
36
+ def bower_javascript
37
+ bower_yaml.fetch('bower_components').fetch('js').map do |filename|
38
+ File.read('bower_components/' + filename)
39
+ end.join
40
+ end
41
+
42
+ def vendor_javascript
43
+ bower_yaml.fetch('vendor').fetch('coffee').map do |filename|
44
+ CoffeeScript.compile(File.read('vendor/' + filename))
45
+ end.join
46
+ end
47
+
48
+ def bower_yaml
49
+ YAML.load(File.read('src/vendor_and_bower_components.yaml'))
50
+ end
51
+ end
@@ -12,6 +12,13 @@ module Rugular
12
12
  "(set in lib/rugular/tasks/server/Procfile)"
13
13
  )
14
14
 
15
+ def add_template_application_sass_file
16
+ FileUtils.cp(
17
+ "#{lib_directory}/templates/server/application.sass",
18
+ "#{destination_root}/.application.sass"
19
+ )
20
+ end
21
+
15
22
  def start_server
16
23
  system(
17
24
  "bundle exec foreman start --color --root=#{destination_root} " \
@@ -24,5 +31,9 @@ module Rugular
24
31
  def rugular_procfile
25
32
  "#{__dir__}/server/Procfile"
26
33
  end
34
+
35
+ def lib_directory
36
+ __dir__.chomp('tasks')
37
+ end
27
38
  end
28
39
  end
@@ -1,2 +1 @@
1
- body
2
- background-color: red
1
+ // Add your directive styles here
@@ -8,11 +8,10 @@ angular.module('<%= name %>').controller('<%= name %>Controller', <%= name %>Con
8
8
 
9
9
  <%= name %> = ->
10
10
  directive =
11
- bindToController: true
12
11
  controller: <%= name %>Controller
13
12
  controllerAs: 'vm'
14
13
  restrict: 'E'
15
- templateUrl: 'components/<%= name %>/<%= name %>.html'
14
+ templateUrl: "components/<%= name %>/<%= name %>.html"
16
15
  scope:
17
16
  number: '='
18
17
 
@@ -3,7 +3,7 @@ AppRouting = ($stateProvider, $urlRouterProvider) ->
3
3
 
4
4
  $stateProvider.state 'root',
5
5
  url: '/'
6
- templateUrl: './app/app.html'
6
+ templateUrl: "app/app.html"
7
7
  controller: 'AppController'
8
8
  controllerAs: 'app'
9
9
 
@@ -1,2 +1 @@
1
- body
2
- background-color: red
1
+ // Add styles for your module here
@@ -5,7 +5,6 @@
5
5
 
6
6
  -# add a list of bower css and javascript files you wish to include in the
7
7
  -# bower_components.yml file
8
-
9
8
  %link(href='bower_components.css', media='screen', rel='stylesheet')
10
9
  %link(href='application.css', media='screen', rel='stylesheet')
11
10
 
@@ -14,5 +13,7 @@
14
13
 
15
14
  %ui-view
16
15
 
16
+ -# Do not change these two lines, the application.js file is the manifest
17
+ -# file in dist
17
18
  %script(src='bower_components.js')
18
19
  %script(src='application.js')
@@ -4,7 +4,7 @@
4
4
  "description": "",
5
5
  "authors": [
6
6
  ],
7
- "license": "MIT",
7
+ "license": "Copyright by the code's authors on the master branch of this repository",
8
8
  "homepage": "",
9
9
  "ignore": [
10
10
  "**/.*",
@@ -9,6 +9,7 @@
9
9
  "coffee-script": "*",
10
10
  "debug": "*",
11
11
  "jshint-stylish": "*",
12
+ "http-server": "*",
12
13
  "karma": "*",
13
14
  "karma-chai": "*",
14
15
  "karma-chai-sinon": "*",
@@ -1,2 +1 @@
1
- body
2
- background-color: red
1
+ // Add styles to your route here
@@ -1,7 +1,7 @@
1
1
  <%= name %>Routing = ($stateProvider) ->
2
- $stateProvider.state '<%= name %>',
3
- url: '/<%= name %>'
4
- templateUrl: '/app/<%= name %>/<%= name %>.html'
2
+ $stateProvider.state 'root.<%= name %>',
3
+ url: '<%= name %>'
4
+ templateUrl: "app/<%= name %>/<%= name %>.html"
5
5
  controller: '<%= name %>Controller'
6
6
  controllerAs: '<%= name %>'
7
7
 
@@ -0,0 +1,2 @@
1
+ @import "vendor/**/*"
2
+ @import "src/**/*"
@@ -1,3 +1,3 @@
1
1
  module Rugular
2
- VERSION = '0.2.9'
2
+ VERSION = '0.4.0'
3
3
  end
data/rugular.gemspec CHANGED
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency 'uglifier', '~> 2'
27
27
  spec.add_runtime_dependency 'foreman', '~> 0'
28
28
  spec.add_runtime_dependency 'thor', '~> 0'
29
- spec.add_runtime_dependency 'bourbon', '~> 4'
30
- spec.add_runtime_dependency 'neat', '~> 1'
29
+ spec.add_runtime_dependency 'sass-globbing', '~> 1'
30
+ spec.add_runtime_dependency 'nokogiri', '~> 1'
31
31
 
32
32
  spec.add_development_dependency 'aruba', '~> 0'
33
33
  spec.add_development_dependency 'byebug', '~> 3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rugular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Shook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-16 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -137,21 +137,21 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: bourbon
140
+ name: sass-globbing
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '4'
145
+ version: '1'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '4'
152
+ version: '1'
153
153
  - !ruby/object:Gem::Dependency
154
- name: neat
154
+ name: nokogiri
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
@@ -256,6 +256,11 @@ files:
256
256
  - lib/rugular/tasks/server/Guardfile
257
257
  - lib/rugular/tasks/server/Procfile
258
258
  - lib/rugular/tasks/server/guards/rugular.rb
259
+ - lib/rugular/tasks/server/guards/rugular_assets.rb
260
+ - lib/rugular/tasks/server/guards/rugular_coffee.rb
261
+ - lib/rugular/tasks/server/guards/rugular_haml.rb
262
+ - lib/rugular/tasks/server/guards/rugular_index_html.rb
263
+ - lib/rugular/tasks/server/guards/rugular_vendor_and_bower_components.rb
259
264
  - lib/rugular/templates/directive/_app.sass.erb
260
265
  - lib/rugular/templates/directive/app.directive.coffee.erb
261
266
  - lib/rugular/templates/directive/app.directive.spec.coffee.erb
@@ -285,6 +290,7 @@ files:
285
290
  - lib/rugular/templates/route/app.haml.erb
286
291
  - lib/rugular/templates/route/app.module.coffee.erb
287
292
  - lib/rugular/templates/route/app.routes.coffee.erb
293
+ - lib/rugular/templates/server/application.sass
288
294
  - lib/rugular/version.rb
289
295
  - rugular.gemspec
290
296
  homepage: http://rugular.info