roger 0.0.1 → 0.10.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 +8 -8
- data/.gitignore +2 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +102 -0
- data/Gemfile +5 -0
- data/MIT_LICENSE +20 -0
- data/README.md +10 -10
- data/Rakefile +9 -0
- data/bin/roger +5 -0
- data/doc/cli.md +46 -0
- data/doc/mockupfile.md +3 -0
- data/doc/templating.md +88 -0
- data/examples/default_template/.gitignore +2 -0
- data/examples/default_template/CHANGELOG +0 -0
- data/examples/default_template/Gemfile +3 -0
- data/examples/default_template/Mockupfile +1 -0
- data/examples/default_template/html/.empty_directory +0 -0
- data/examples/default_template/partials/.empty_directory +0 -0
- data/lib/roger/cli/command.rb +23 -0
- data/lib/roger/cli/generate.rb +5 -0
- data/lib/roger/cli/release.rb +10 -0
- data/lib/roger/cli/serve.rb +29 -0
- data/lib/roger/cli.rb +123 -0
- data/lib/roger/extractor.rb +95 -0
- data/lib/roger/generators/generator.rb +23 -0
- data/lib/roger/generators/new.rb +67 -0
- data/lib/roger/generators/templates/generator.tt +13 -0
- data/lib/roger/generators.rb +23 -0
- data/lib/roger/mockupfile.rb +63 -0
- data/lib/roger/project.rb +92 -0
- data/lib/roger/rack/html_validator.rb +26 -0
- data/lib/roger/rack/roger.rb +52 -0
- data/lib/roger/rack/sleep.rb +21 -0
- data/lib/roger/release/cleaner.rb +47 -0
- data/lib/roger/release/finalizers/dir.rb +29 -0
- data/lib/roger/release/finalizers/git_branch.rb +92 -0
- data/lib/roger/release/finalizers/rsync.rb +77 -0
- data/lib/roger/release/finalizers/zip.rb +42 -0
- data/lib/roger/release/finalizers.rb +19 -0
- data/lib/roger/release/injector.rb +99 -0
- data/lib/roger/release/processors/mockup.rb +93 -0
- data/lib/roger/release/processors/url_relativizer.rb +45 -0
- data/lib/roger/release/processors.rb +17 -0
- data/lib/roger/release/scm/git.rb +101 -0
- data/lib/roger/release/scm.rb +32 -0
- data/lib/roger/release.rb +363 -0
- data/lib/roger/resolver.rb +119 -0
- data/lib/roger/server.rb +117 -0
- data/lib/roger/template.rb +206 -0
- data/lib/roger/w3c_validator.rb +129 -0
- data/roger.gemspec +35 -0
- data/test/Mockupfile-syntax.rb +85 -0
- data/test/project/.rvmrc +1 -0
- data/test/project/Gemfile +7 -0
- data/test/project/Gemfile.lock +38 -0
- data/test/project/Mockupfile +13 -0
- data/test/project/html/formats/erb.html.erb +5 -0
- data/test/project/html/formats/index.html +1 -0
- data/test/project/html/formats/json.json.erb +0 -0
- data/test/project/html/formats/markdown.md +3 -0
- data/test/project/html/formats/mockup.html +5 -0
- data/test/project/html/front_matter/erb.html.erb +16 -0
- data/test/project/html/front_matter/markdown.md +7 -0
- data/test/project/html/layouts/content-for.html.erb +17 -0
- data/test/project/html/layouts/erb.html.erb +19 -0
- data/test/project/html/mockup/encoding.html +3 -0
- data/test/project/html/partials/erb.html.erb +10 -0
- data/test/project/html/partials/load_path.html.erb +3 -0
- data/test/project/html/partials/mockup.html +13 -0
- data/test/project/html/static/non-relative.html.erb +9 -0
- data/test/project/html/static/relative.html.erb +9 -0
- data/test/project/layouts/test.html.erb +34 -0
- data/test/project/layouts/yield.html.erb +1 -0
- data/test/project/lib/generators/test.rb +9 -0
- data/test/project/partials/formats/erb.html.erb +1 -0
- data/test/project/partials/partials-test.html.erb +1 -0
- data/test/project/partials/test/erb.html.erb +1 -0
- data/test/project/partials/test/front_matter.html.erb +1 -0
- data/test/project/partials/test/json.json.erb +1 -0
- data/test/project/partials/test/markdown.md +1 -0
- data/test/project/partials/test/mockup.part.html +1 -0
- data/test/project/partials/test/simple.html.erb +1 -0
- data/test/project/partials2/partials2-test.html.erb +1 -0
- data/test/unit/cli_test.rb +12 -0
- data/test/unit/generators_test.rb +75 -0
- data/test/unit/release/cleaner_test.rb +47 -0
- data/test/unit/resolver_test.rb +92 -0
- data/test/unit/template_test.rb +127 -0
- metadata +202 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDYwN2JiYWE4N2QzYjdkYzhjNTRiYWQ3NTdkMWU3OGU4NWI0MTIxMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzZjMjM2MjcyY2U5ODBhMTk5MDBiNTQ3OGFjODNlNGVmZWM2ZmZlMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTM3NmYzNjkyNTIzZmUzMzI1OGZlOTQ2M2JkZDNkMjg1MWE5ODQ5Mjk4MGI3
|
10
|
+
ZTQ1ZTUyNzY4OGJiNzM5ZTQwNDk4OTAxMDIxNzIxMjJlOGFkN2E4YjMzNGQy
|
11
|
+
YmRhZjUxODk1Mzc3MmM1N2I5ZjJjYjVlNTI5MTIxNzhjYjBkZWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTA2OGU2NDg0MTFjMWI4ZWU2YzNiZmU2NzE1ZjhlOTk0MTQ5ZTNmMGY3Nzg0
|
14
|
+
MTY2ZGMxMzJmODQ0Y2M2MzhlODQyMGY2YTUxMTQ0NWQ2MjkzMjEwYThlYzRh
|
15
|
+
MzMyMzc1Y2Q4Zjc3OGVhNWU3OTYwODgwODk1NWQxN2UyZmQ5ZGY=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 0.10.0
|
4
|
+
* Welcome **Roger**
|
5
|
+
* Removed requirejs, sass and yuicompressor processors in favour of separate gems
|
6
|
+
* Removed legacy templates using `<!-- [START:...] -->` partials (still available in separate gem)
|
7
|
+
|
8
|
+
## Version 0.9.0
|
9
|
+
* More documentation!
|
10
|
+
* More tests! (and CI!)
|
11
|
+
* Thor and Tilt updates
|
12
|
+
* Add possibility to load external generators from gems (with the `Roger::Generators::Base.register` method)
|
13
|
+
* Partials now automatically prefer templates of the same extension as the parent
|
14
|
+
* ERB Templates now support `content_for(:name) do ... end` blocks which can be yielded by `:name` in the layout
|
15
|
+
* Multiple load paths for partials are now supported
|
16
|
+
* Minor changes and fixes
|
17
|
+
* First preparations for version 1.0.0. which will be called **Roger**
|
18
|
+
|
19
|
+
## Version 0.8.4
|
20
|
+
* Fix requirejs processor to clean up the correct paths
|
21
|
+
* Allow typing of Y to rsync instead of full "yes"
|
22
|
+
|
23
|
+
## Version 0.8.3
|
24
|
+
* Make the url relativizer respect :skip parameter
|
25
|
+
|
26
|
+
## Version 0.8.2
|
27
|
+
* If bundler is installed we're running Bundler.require automatically.
|
28
|
+
|
29
|
+
## Version 0.8.1
|
30
|
+
* Don't crash on non-existent partials/layouts path
|
31
|
+
* Add more logging in verbose mode when extracting mockup
|
32
|
+
* Fix the passing of env options to mockup release processor
|
33
|
+
|
34
|
+
## Version 0.8.0
|
35
|
+
* Set content type header in response when rendering templates
|
36
|
+
* Add option to prompt user before performing rsync finalizer (defaults to true)
|
37
|
+
* Fix zip finalizer to use options[:zip] in actuall executed command too
|
38
|
+
* Logger now outputs color and has support for warning messages
|
39
|
+
* Mockup templating is now fully handled with Tilt
|
40
|
+
* Mockup extraction and URL relativization etc. for release are now done in their respective processors (will be added automatically if you haven't added them yourself.) This gives a fine-grained control over the point in time when these processors are ran.
|
41
|
+
* Add a testproject to the repository
|
42
|
+
* Add support for layouts
|
43
|
+
* Add a `git_branch` finalizer that allows us to release to a branch on a repository (this makes it easy to release github pages)
|
44
|
+
* Allow requirejs processor to work wih single files as well
|
45
|
+
* Expose server options to mockup so you can configure a https server if you want
|
46
|
+
* Minor fixes
|
47
|
+
|
48
|
+
## Version 0.7.4
|
49
|
+
* Allow for underscores in .scss files when releasing
|
50
|
+
|
51
|
+
## Version 0.7.3
|
52
|
+
* Set a sensible `load_path` for sass in release mode (defaults to `build_path + "stylesheets"`)
|
53
|
+
* Also automatically require the rsync finalizers
|
54
|
+
|
55
|
+
## Version 0.7.2
|
56
|
+
* Add zip finalizers
|
57
|
+
* Instead of complaining about existing build path, just clean it up
|
58
|
+
* Instead of complaining about unexisting target path, just create it
|
59
|
+
* Automatically require all built-in procssors
|
60
|
+
|
61
|
+
## Version 0.7.1
|
62
|
+
* Pass target_file to the ERBTemplate to files with erb errors
|
63
|
+
* Fix env["MOCKUP_PROJECT"] setting in extractor
|
64
|
+
|
65
|
+
## Version 0.7.0
|
66
|
+
* Replace --quiet with -s in as it's no longer supported in newer GIT versions
|
67
|
+
* Add support for ENV passing to the partials
|
68
|
+
* Add support for single file processing and env passing in the extractor (release)
|
69
|
+
* Refactor path and url resolving
|
70
|
+
* Allow `.html` files to be processed by ERB (both in release and serve)
|
71
|
+
* Pass "MOCKUP_PROJECT" variable to env (both in release and serve)
|
72
|
+
|
73
|
+
## Version 0.6.5
|
74
|
+
* Allow disabling of URL relativizing in the extractor with `release.extract :url_relativize => false`
|
75
|
+
* Add missing Hpricot dependency to gem
|
76
|
+
|
77
|
+
## Version 0.6.4
|
78
|
+
* Add RsyncFinalizer to automatically upload your mockup
|
79
|
+
|
80
|
+
## Version 0.6.3
|
81
|
+
* Add license to gemspec
|
82
|
+
* Fix default_template in gem
|
83
|
+
* Add option to allow for resolving urls in custom attributes in the extractor (via `release.extract(options_hash)`)
|
84
|
+
* Add more unified interface to finalizers and processors
|
85
|
+
* Fix error if node can't be found in Processors::Requirejs
|
86
|
+
|
87
|
+
## Version 0.6.2
|
88
|
+
* Improved cleaner with more robust tests
|
89
|
+
|
90
|
+
## Version 0.6.1
|
91
|
+
* Correctly pass file and linenumber to Mockupfile evaluation
|
92
|
+
* Add the tilt gem as a requirement (needed for injectors in release)
|
93
|
+
* Make the cleaner also remove directories, also make it more safe (it will never delete stuff above the build_path)
|
94
|
+
|
95
|
+
## Version 0.6.0
|
96
|
+
* Pass command line options to underlying objets
|
97
|
+
* Update docs
|
98
|
+
* The different Processors, injections and cleanups are run in order as specified. Finalizers will always be run last in their own order.
|
99
|
+
* Replace CLI "generate" command with "new" subcommand and add support for remote git skeletons based on Thor templating.
|
100
|
+
* Add most simple mockup directory as default_template
|
101
|
+
* Requirejs processor updated so it will search for a global r.js command, a local npm r.js command and a vendored r.js command
|
102
|
+
* Minor fixes and changes
|
data/Gemfile
ADDED
data/MIT_LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Flurin Egger, DigitPaint (http://www.digitpaint.nl)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# Roger
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/roger)
|
4
|
+
[](https://travis-ci.org/DigitPaint/roger)
|
5
5
|
|
6
6
|
## What is it?
|
7
7
|
|
8
|
-
|
8
|
+
Roger is your friendly front-end development toolbox! It helps you with these 4 things:
|
9
9
|
|
10
10
|
1. **Generate** : Set up your projects
|
11
11
|
1. **Serve** : Development server
|
@@ -16,10 +16,10 @@ HtmlMockup is your friendly front-end development toolbox! It helps you with the
|
|
16
16
|
|
17
17
|
We assume you have a working Ruby 1.9.x or higher running.
|
18
18
|
|
19
|
-
1. Install
|
19
|
+
1. Install Roger
|
20
20
|
|
21
21
|
```shell
|
22
|
-
gem install
|
22
|
+
gem install roger
|
23
23
|
```
|
24
24
|
|
25
25
|
1. Create a new project
|
@@ -48,15 +48,15 @@ We assume you have a working Ruby 1.9.x or higher running.
|
|
48
48
|
|
49
49
|
Read more documentation:
|
50
50
|
|
51
|
-
* [**Templating** Learn the power of
|
51
|
+
* [**Templating** Learn the power of Roger built in templating](doc/templating.md)
|
52
52
|
* [**CLI** Learn about the different `mockup` commands](doc/cli.md)
|
53
53
|
* [**Mockupfile** Learn how to configure and extend your Project](doc/mockupfile.md)
|
54
54
|
|
55
55
|
## Why?
|
56
56
|
|
57
|
-
When we started with
|
57
|
+
When we started with Roger there was no Grunt/Gulp/whatever and with us being a Ruby shop we wrote Roger. Since its beginning it has evolved into quite a powerful tool.
|
58
58
|
|
59
|
-
Why would
|
59
|
+
Why would Roger be better than any other?
|
60
60
|
It's not it just does some things differently.
|
61
61
|
|
62
62
|
* Ruby
|
@@ -67,7 +67,7 @@ It's not it just does some things differently.
|
|
67
67
|
|
68
68
|
## Contributors
|
69
69
|
|
70
|
-
[View contributors](https://github.com/digitpaint/
|
70
|
+
[View contributors](https://github.com/digitpaint/roger/graphs/contributors)
|
71
71
|
|
72
72
|
## License
|
73
73
|
|
data/Rakefile
ADDED
data/bin/roger
ADDED
data/doc/cli.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Command Line Interface
|
2
|
+
|
3
|
+
The easiest way to get help is through the commandline by running
|
4
|
+
|
5
|
+
```shell
|
6
|
+
mockup help
|
7
|
+
```
|
8
|
+
|
9
|
+
or to get help on a specific subcommand
|
10
|
+
|
11
|
+
```shell
|
12
|
+
mockup help [subcommand]
|
13
|
+
```
|
14
|
+
|
15
|
+
## Generate
|
16
|
+
|
17
|
+
```shell
|
18
|
+
mockup generate [generator] [options]
|
19
|
+
```
|
20
|
+
|
21
|
+
## Serve
|
22
|
+
|
23
|
+
```shell
|
24
|
+
mockup serve [options]
|
25
|
+
```
|
26
|
+
|
27
|
+
Starts a webserver (port 9000 by default)
|
28
|
+
|
29
|
+
|
30
|
+
## Release
|
31
|
+
|
32
|
+
```shell
|
33
|
+
mockup release [options]
|
34
|
+
```
|
35
|
+
|
36
|
+
Releases the project
|
37
|
+
|
38
|
+
## Global options
|
39
|
+
|
40
|
+
All commands accept these options.
|
41
|
+
|
42
|
+
```
|
43
|
+
Options:
|
44
|
+
-v, [--verbose] # Set's verbose output
|
45
|
+
-h, [--help] # Help
|
46
|
+
```
|
data/doc/mockupfile.md
ADDED
data/doc/templating.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Templating
|
2
|
+
|
3
|
+
## Directories
|
4
|
+
|
5
|
+
Before we get started, it's good to know that there are a couple of "special" folders within any Roger project. Don't worry, you can configure these; they're not hard-coded. The folders are:
|
6
|
+
|
7
|
+
* **project-path** this is the main directory containing the Mockupfile and all other directories.
|
8
|
+
* **html-path** this is the directory where all your HTML/CSS/Javascript will go (in subdirectories of course).
|
9
|
+
* **partials-path** this is the directory where all partials reside.
|
10
|
+
* **layouts-path** this is the directory where the layouts hang out.
|
11
|
+
|
12
|
+
The default project tree looks like this:
|
13
|
+
|
14
|
+
```
|
15
|
+
project-path
|
16
|
+
|
|
17
|
+
|- html (html-path)
|
18
|
+
|
|
19
|
+
|- partials (partials-path)
|
20
|
+
|
|
21
|
+
\- layouts (layouts-path)
|
22
|
+
```
|
23
|
+
|
24
|
+
Only the html-path has to exist. The others are not required.
|
25
|
+
|
26
|
+
## HTML
|
27
|
+
|
28
|
+
The html-path is actually the root for all you front-end code. This is what will be served as the document-root with `mockup serve` and will be the base for a release when using `mockup release`.
|
29
|
+
|
30
|
+
In the html-path you can put static files (images, documents, etc.) but also templates. Anything that the [Tilt Engine](https://github.com/rtomayko/tilt) can handle is ok. The only thing Mockup adds is handling for front-matter, layouts and partials.
|
31
|
+
|
32
|
+
## Front-matter
|
33
|
+
|
34
|
+
Every template can optionally start with a bit of front-matter. Front-matter is defined as follows:
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
---
|
38
|
+
key: value
|
39
|
+
---
|
40
|
+
```
|
41
|
+
|
42
|
+
Front-matter is parsed as YAML and can contain data to be used in the template, layout or partial. You can access
|
43
|
+
these values in the templates (layouts and partials included) by using `document.KEY`.
|
44
|
+
|
45
|
+
## Layouts
|
46
|
+
|
47
|
+
Layouts are basically "wrap" templates. The layout will wrap around the rendered template. In the template front-matter you define what layout it should use by setting the `layout` key.
|
48
|
+
|
49
|
+
### An example
|
50
|
+
|
51
|
+
|
52
|
+
#### html/template.html.erb
|
53
|
+
```erb
|
54
|
+
---
|
55
|
+
layout: default
|
56
|
+
---
|
57
|
+
Template
|
58
|
+
```
|
59
|
+
|
60
|
+
#### layouts/default.html.erb
|
61
|
+
```erb
|
62
|
+
Layout (before)
|
63
|
+
<% yield %>
|
64
|
+
Layout (after)
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Results
|
68
|
+
This would result in:
|
69
|
+
|
70
|
+
```
|
71
|
+
Layout (before)
|
72
|
+
Template
|
73
|
+
Layout (after)
|
74
|
+
```
|
75
|
+
|
76
|
+
## Partials
|
77
|
+
|
78
|
+
Partials are little pieces of template that can be easily reused. You can access the partials throught the `partial("partialpath")` method. You can optionall pass variables to the partial by passing a ruby hash of options as a second parameter. This works like this:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
partial("path/to/partial/relative/to/partials-path", {:key => "value"})
|
82
|
+
```
|
83
|
+
|
84
|
+
In the partial these can be accessed as local variables. So for instance in you `test.html.erb` partial that would look like this:
|
85
|
+
|
86
|
+
```erb
|
87
|
+
<%= key %>
|
88
|
+
```
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
# Configure your mockup here
|
File without changes
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Roger
|
2
|
+
|
3
|
+
class Cli::Command < Thor::Group
|
4
|
+
|
5
|
+
class_option :verbose,
|
6
|
+
:desc => "Set's verbose output",
|
7
|
+
:aliases => ["-v"],
|
8
|
+
:default => false,
|
9
|
+
:type => :boolean
|
10
|
+
|
11
|
+
def initialize_project
|
12
|
+
@project = Cli::Base.project
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def project_banner(project)
|
18
|
+
puts " Html: \"#{project.html_path}\""
|
19
|
+
puts " Partials: \"#{project.partial_path}\""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Roger
|
2
|
+
class Cli::Serve < Cli::Command
|
3
|
+
|
4
|
+
|
5
|
+
desc "Serve the current project"
|
6
|
+
|
7
|
+
class_options :port => :string, # Defaults to 9000
|
8
|
+
:handler => :string, # The handler to use (defaults to mongrel)
|
9
|
+
:validate => :boolean # Run validation?
|
10
|
+
|
11
|
+
def serve
|
12
|
+
|
13
|
+
server_options = {}
|
14
|
+
options.each{|k,v| server_options[k.to_sym] = v }
|
15
|
+
server_options[:server] = {}
|
16
|
+
[:port, :handler, :validate].each do |k|
|
17
|
+
server_options[:server][k] = server_options.delete(k) if server_options.has_key?(k)
|
18
|
+
end
|
19
|
+
|
20
|
+
server = @project.server
|
21
|
+
server.set_options(server_options[:server])
|
22
|
+
|
23
|
+
puts "Running Roger with #{server.handler.inspect} on port #{server.port}"
|
24
|
+
puts project_banner(@project)
|
25
|
+
|
26
|
+
server.run!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/roger/cli.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Require bundler gems if available
|
4
|
+
if Object.const_defined?(:Bundler)
|
5
|
+
Bundler.require(:default)
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
require 'thor'
|
10
|
+
require 'thor/group'
|
11
|
+
|
12
|
+
require 'pathname'
|
13
|
+
require 'fileutils'
|
14
|
+
include FileUtils
|
15
|
+
|
16
|
+
require File.dirname(__FILE__) + "/template"
|
17
|
+
require File.dirname(__FILE__) + "/project"
|
18
|
+
require File.dirname(__FILE__) + "/w3c_validator"
|
19
|
+
|
20
|
+
|
21
|
+
module Roger
|
22
|
+
module Cli; end
|
23
|
+
end
|
24
|
+
|
25
|
+
require File.dirname(__FILE__) + "/cli/command"
|
26
|
+
require File.dirname(__FILE__) + "/cli/serve"
|
27
|
+
require File.dirname(__FILE__) + "/cli/release"
|
28
|
+
require File.dirname(__FILE__) + "/cli/generate"
|
29
|
+
|
30
|
+
require File.dirname(__FILE__) + "/generators"
|
31
|
+
|
32
|
+
|
33
|
+
module Roger
|
34
|
+
class Cli::Base < Thor
|
35
|
+
|
36
|
+
def initialize(*args)
|
37
|
+
super
|
38
|
+
self.class.project = initialize_project
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
attr_accessor :project
|
43
|
+
end
|
44
|
+
|
45
|
+
class_option :path,
|
46
|
+
:desc => "Project root path",
|
47
|
+
:type => :string,
|
48
|
+
:required => false,
|
49
|
+
:default => "."
|
50
|
+
|
51
|
+
class_option :html_path,
|
52
|
+
:desc => 'The document root, defaults to "[directory]/html"',
|
53
|
+
:type => :string
|
54
|
+
|
55
|
+
|
56
|
+
class_option :partial_path,
|
57
|
+
:desc => 'Defaults to [directory]/partials',
|
58
|
+
:type => :string
|
59
|
+
|
60
|
+
register Cli::Generate, "generate", "generate [COMMAND]", "Run a generator"
|
61
|
+
|
62
|
+
register Cli::Serve, "serve", "serve #{Cli::Serve.arguments.map{ |arg| arg.banner }.join(" ")}", Cli::Serve.desc
|
63
|
+
self.tasks["serve"].options = Cli::Serve.class_options
|
64
|
+
|
65
|
+
register Cli::Release, "release", "release #{Cli::Release.arguments.map{ |arg| arg.banner }.join(" ")}", Cli::Release.desc
|
66
|
+
self.tasks["release"].options = Cli::Release.class_options
|
67
|
+
|
68
|
+
desc "validate [directory/file]", "Validates the file or all HTML in directory"
|
69
|
+
method_options :show_valid => :boolean, # Also print a line for each valid file
|
70
|
+
:filter => :string # What files should be found, defaults to [^_]*.html
|
71
|
+
def validate(path=".")
|
72
|
+
filter = options["filter"] || "[^_]*.html"
|
73
|
+
|
74
|
+
puts "Filtering on #{options["filter"]}" if options["filter"]
|
75
|
+
|
76
|
+
if File.directory?(path)
|
77
|
+
any_invalid = false
|
78
|
+
|
79
|
+
if (files = Dir.glob("#{path}/**/#{filter}")).any?
|
80
|
+
files.each do |file|
|
81
|
+
if !self.w3cvalidate(file)
|
82
|
+
any_invalid = true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
if !any_invalid
|
86
|
+
puts "All files were considered valid"
|
87
|
+
end
|
88
|
+
else
|
89
|
+
puts "No files matched \"#{filter}\""
|
90
|
+
end
|
91
|
+
elsif File.readable?(path)
|
92
|
+
self.w3cvalidate(path)
|
93
|
+
else
|
94
|
+
puts "No such file/directory #{path}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
# TODO: handle options
|
101
|
+
def initialize_project
|
102
|
+
if((Pathname.new(options[:path]) + "../partials").exist?)
|
103
|
+
puts "[ERROR]: Don't use the \"html\" path, use the project base path instead"
|
104
|
+
exit(1)
|
105
|
+
end
|
106
|
+
|
107
|
+
Project.new(options[:path], {:shell => self.shell}.update(options))
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
def w3cvalidate(file)
|
112
|
+
validator = W3CValidator.new(File.read(file))
|
113
|
+
validator.validate!
|
114
|
+
if !options["show_valid"] && !validator.valid || options["show_valid"]
|
115
|
+
print "- #{file} "
|
116
|
+
print "(errors: #{validator.errors}, warnings: #{validator.warnings})\n"
|
117
|
+
end
|
118
|
+
validator.valid
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|