brandish 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +41 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +9 -0
- data/bin/brandish +16 -0
- data/brandish.gemspec +39 -0
- data/defaults/templates/html.liquid +39 -0
- data/lib/brandish.rb +51 -0
- data/lib/brandish/application.rb +163 -0
- data/lib/brandish/application/bench_command.rb +96 -0
- data/lib/brandish/application/build_command.rb +73 -0
- data/lib/brandish/application/initialize_command.rb +83 -0
- data/lib/brandish/application/serve_command.rb +150 -0
- data/lib/brandish/configure.rb +196 -0
- data/lib/brandish/configure/dsl.rb +135 -0
- data/lib/brandish/configure/dsl/form.rb +136 -0
- data/lib/brandish/configure/form.rb +32 -0
- data/lib/brandish/errors.rb +65 -0
- data/lib/brandish/execute.rb +26 -0
- data/lib/brandish/markup.rb +10 -0
- data/lib/brandish/markup/redcarpet.rb +14 -0
- data/lib/brandish/markup/redcarpet/format.rb +127 -0
- data/lib/brandish/markup/redcarpet/html.rb +95 -0
- data/lib/brandish/parser.rb +26 -0
- data/lib/brandish/parser/main.rb +237 -0
- data/lib/brandish/parser/node.rb +89 -0
- data/lib/brandish/parser/node/block.rb +98 -0
- data/lib/brandish/parser/node/command.rb +102 -0
- data/lib/brandish/parser/node/pair.rb +42 -0
- data/lib/brandish/parser/node/root.rb +83 -0
- data/lib/brandish/parser/node/string.rb +18 -0
- data/lib/brandish/parser/node/text.rb +114 -0
- data/lib/brandish/path_set.rb +163 -0
- data/lib/brandish/processor.rb +47 -0
- data/lib/brandish/processor/base.rb +144 -0
- data/lib/brandish/processor/block.rb +47 -0
- data/lib/brandish/processor/command.rb +47 -0
- data/lib/brandish/processor/context.rb +169 -0
- data/lib/brandish/processor/descend.rb +32 -0
- data/lib/brandish/processor/inline.rb +49 -0
- data/lib/brandish/processor/name_filter.rb +67 -0
- data/lib/brandish/processor/pair_filter.rb +96 -0
- data/lib/brandish/processors.rb +26 -0
- data/lib/brandish/processors/all.rb +19 -0
- data/lib/brandish/processors/all/comment.rb +29 -0
- data/lib/brandish/processors/all/embed.rb +56 -0
- data/lib/brandish/processors/all/if.rb +109 -0
- data/lib/brandish/processors/all/import.rb +95 -0
- data/lib/brandish/processors/all/literal.rb +42 -0
- data/lib/brandish/processors/all/verify.rb +47 -0
- data/lib/brandish/processors/common.rb +20 -0
- data/lib/brandish/processors/common/asset.rb +118 -0
- data/lib/brandish/processors/common/asset/paths.rb +93 -0
- data/lib/brandish/processors/common/group.rb +67 -0
- data/lib/brandish/processors/common/header.rb +86 -0
- data/lib/brandish/processors/common/markup.rb +127 -0
- data/lib/brandish/processors/common/output.rb +73 -0
- data/lib/brandish/processors/html.rb +18 -0
- data/lib/brandish/processors/html/group.rb +33 -0
- data/lib/brandish/processors/html/header.rb +46 -0
- data/lib/brandish/processors/html/markup.rb +131 -0
- data/lib/brandish/processors/html/output.rb +62 -0
- data/lib/brandish/processors/html/output/document.rb +127 -0
- data/lib/brandish/processors/html/script.rb +64 -0
- data/lib/brandish/processors/html/script/babel.rb +48 -0
- data/lib/brandish/processors/html/script/coffee.rb +47 -0
- data/lib/brandish/processors/html/script/vanilla.rb +45 -0
- data/lib/brandish/processors/html/style.rb +82 -0
- data/lib/brandish/processors/html/style/highlight.rb +89 -0
- data/lib/brandish/processors/html/style/sass.rb +64 -0
- data/lib/brandish/processors/html/style/vanilla.rb +71 -0
- data/lib/brandish/processors/latex.rb +15 -0
- data/lib/brandish/processors/latex/markup.rb +47 -0
- data/lib/brandish/scanner.rb +64 -0
- data/lib/brandish/version.rb +9 -0
- data/templates/initialize/Gemfile.tt +14 -0
- data/templates/initialize/brandish.config.rb.tt +49 -0
- metadata +296 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 86feab5398244c93d5f1611dd767c8729ae38496
|
|
4
|
+
data.tar.gz: d7052a18a14e35af428f52d7813bb477486ebbfb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c966e40a9ee589b88dce82aae60599a84d8329554c2e1d51a4a5c1f1c79ef27473263c07856456d0ab4538933b86f2383d36c168ce4a84be29ede33861d2d31b
|
|
7
|
+
data.tar.gz: 1baea0c61653b3469b1dac38f360c39c9c80133a5fd748673057874893821d1d3c90ef9a99aef8b7498f04502a66882895d4759a7ab88b26f8923a3da36149b0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.3
|
|
3
|
+
|
|
4
|
+
Metrics/LineLength:
|
|
5
|
+
Enabled: false
|
|
6
|
+
Metrics/MethodLength:
|
|
7
|
+
Max: 15
|
|
8
|
+
Metrics/BlockLength:
|
|
9
|
+
Exclude:
|
|
10
|
+
- 'spec/*.rb'
|
|
11
|
+
- 'spec/**/*.rb'
|
|
12
|
+
- 'brandish.gemspec'
|
|
13
|
+
Metrics/AbcSize:
|
|
14
|
+
Max: 25
|
|
15
|
+
|
|
16
|
+
Style/AlignParameters:
|
|
17
|
+
EnforcedStyle: with_fixed_indentation
|
|
18
|
+
Style/SignalException:
|
|
19
|
+
EnforcedStyle: only_fail
|
|
20
|
+
Style/AccessModifierIndentation:
|
|
21
|
+
EnforcedStyle: outdent
|
|
22
|
+
Style/Documentation:
|
|
23
|
+
Enabled: false
|
|
24
|
+
Style/Encoding:
|
|
25
|
+
Enabled: true
|
|
26
|
+
EnforcedStyle: always
|
|
27
|
+
AutoCorrectEncodingComment: "# encoding: utf-8\n"
|
|
28
|
+
Style/RegexpLiteral:
|
|
29
|
+
EnforcedStyle: mixed
|
|
30
|
+
Style/StringLiterals:
|
|
31
|
+
EnforcedStyle: double_quotes
|
|
32
|
+
Style/AlignHash:
|
|
33
|
+
EnforcedLastArgumentHashStyle: ignore_implicit
|
|
34
|
+
Style/AlignArray:
|
|
35
|
+
Enabled: false
|
|
36
|
+
Style/IndentArray:
|
|
37
|
+
Enabled: false
|
|
38
|
+
Style/Alias:
|
|
39
|
+
EnforcedStyle: prefer_alias_method
|
|
40
|
+
Style/ParallelAssignment:
|
|
41
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-m markdown
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at me@medcat.me. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Jeremy Rodi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Brandish
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/brandish`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'brandish'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install brandish
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/medcat/brandish. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
41
|
+
|
data/Rakefile
ADDED
data/bin/brandish
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
5
|
+
load_path = File.expand_path(File.join(__FILE__, "../../lib"))
|
|
6
|
+
$LOAD_PATH.unshift(load_path) unless $LOAD_PATH.include?(load_path)
|
|
7
|
+
require "brandish"
|
|
8
|
+
require "brandish/application"
|
|
9
|
+
|
|
10
|
+
class Object
|
|
11
|
+
def taint
|
|
12
|
+
fail
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
Brandish::Application.call
|
data/brandish.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
6
|
+
require "brandish/version"
|
|
7
|
+
|
|
8
|
+
Gem::Specification.new do |spec|
|
|
9
|
+
spec.name = "brandish"
|
|
10
|
+
spec.version = Brandish::VERSION
|
|
11
|
+
spec.authors = ["Jeremy Rodi"]
|
|
12
|
+
spec.email = ["me@medcat.me"]
|
|
13
|
+
|
|
14
|
+
spec.summary = "A markup language for compiling to different formats."
|
|
15
|
+
spec.description = spec.summary
|
|
16
|
+
spec.homepage = "https://github.com/medcat/brandish"
|
|
17
|
+
spec.license = "MIT"
|
|
18
|
+
|
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = "bin"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_dependency "hanami-helpers", "~> 0.5"
|
|
27
|
+
spec.add_dependency "thor", "~> 0.19"
|
|
28
|
+
spec.add_dependency "commander", "~> 4.4"
|
|
29
|
+
spec.add_dependency "listen", "~> 3.0"
|
|
30
|
+
spec.add_dependency "sass", "~> 3.4"
|
|
31
|
+
spec.add_dependency "yoga", "~> 0.4"
|
|
32
|
+
spec.add_dependency "liquid", "~> 4.0"
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
37
|
+
spec.add_development_dependency "simplecov", "~> 0.13"
|
|
38
|
+
spec.add_development_dependency "rubocop", "~> 0.47"
|
|
39
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<html lang="en">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
|
|
7
|
+
<title>{{ title | escape }}</title>
|
|
8
|
+
<meta name="description" content="{{ description | escape }}">
|
|
9
|
+
<meta name="author" content="{{ author | escape }}">
|
|
10
|
+
|
|
11
|
+
{% for style in styles %}
|
|
12
|
+
{% if style.inline? %}
|
|
13
|
+
{% comment %}
|
|
14
|
+
Style and Script tags, in HTML5, are CDATA. No escaping needed.
|
|
15
|
+
{% endcomment %}
|
|
16
|
+
<style>{{ style.content }}</style>
|
|
17
|
+
{% else %}
|
|
18
|
+
<link rel="stylesheet" href="{{ style.content | escape }}">
|
|
19
|
+
{% endif %}
|
|
20
|
+
{% endfor %}
|
|
21
|
+
</head>
|
|
22
|
+
|
|
23
|
+
<body>
|
|
24
|
+
<div id="container">
|
|
25
|
+
{{ content }}
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
{% for script in scripts %}
|
|
29
|
+
{% if script.inline? %}
|
|
30
|
+
{% comment %}
|
|
31
|
+
Style and Script tags, in HTML5, are CDATA. No escaping needed.
|
|
32
|
+
{% endcomment %}
|
|
33
|
+
<script>{{ script.content }}</script>
|
|
34
|
+
{% else %}
|
|
35
|
+
<script src="{{ script.content | escape }}"></script>
|
|
36
|
+
{% endif %}
|
|
37
|
+
{% endfor %}
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
data/lib/brandish.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "brandish/version"
|
|
5
|
+
require "brandish/errors"
|
|
6
|
+
require "brandish/path_set"
|
|
7
|
+
require "brandish/configure"
|
|
8
|
+
require "brandish/scanner"
|
|
9
|
+
require "brandish/parser"
|
|
10
|
+
require "brandish/markup"
|
|
11
|
+
require "brandish/processor"
|
|
12
|
+
require "brandish/processors"
|
|
13
|
+
|
|
14
|
+
# A library to format text.
|
|
15
|
+
module Brandish
|
|
16
|
+
# @overload self.configuration(&block)
|
|
17
|
+
# Sets the configuration object to a new {Configure} object, and builds it
|
|
18
|
+
# using {Configure::DSL.call}. The configuration object is then returned.
|
|
19
|
+
#
|
|
20
|
+
# @yield
|
|
21
|
+
# @return [Configure]
|
|
22
|
+
# @overload self.configuration
|
|
23
|
+
# Returns the current configuration object.
|
|
24
|
+
#
|
|
25
|
+
# @return [Configure]
|
|
26
|
+
def self.configuration(root = ::Dir.pwd)
|
|
27
|
+
if block_given?
|
|
28
|
+
@configuration ||= Configure.new(::File.expand_path(root))
|
|
29
|
+
Configure::DSL.call(@configuration, &::Proc.new)
|
|
30
|
+
else
|
|
31
|
+
@configuration
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Sets the configuration object to a new {Configure} object, and builds it
|
|
36
|
+
# using {Configure::DSL.call}. The configuration object is then returned.
|
|
37
|
+
#
|
|
38
|
+
# @yield
|
|
39
|
+
# @return [Configure]
|
|
40
|
+
def self.configure(&b)
|
|
41
|
+
configuration(&b)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Resets the configuration object, so that it can be redefined. This is
|
|
45
|
+
# used to clear out the previous configuration.
|
|
46
|
+
#
|
|
47
|
+
# @return [void]
|
|
48
|
+
def self.reset_configuration
|
|
49
|
+
@configuration = nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "webrick"
|
|
5
|
+
require "pathname"
|
|
6
|
+
require "commander"
|
|
7
|
+
require "listen"
|
|
8
|
+
require "brandish/application/bench_command"
|
|
9
|
+
require "brandish/application/build_command"
|
|
10
|
+
require "brandish/application/initialize_command"
|
|
11
|
+
require "brandish/application/serve_command"
|
|
12
|
+
|
|
13
|
+
module Brandish
|
|
14
|
+
# The command line interface for Brandish.
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
class Application
|
|
18
|
+
include Commander::Methods
|
|
19
|
+
|
|
20
|
+
# The name of the configure file. This should be `"brandish.config.rb"`,
|
|
21
|
+
# but may change in the future (maybe `Brandishfile`?).
|
|
22
|
+
#
|
|
23
|
+
# @return [::String]
|
|
24
|
+
attr_reader :config_file
|
|
25
|
+
|
|
26
|
+
# The executing directory for the application. This is provided with the
|
|
27
|
+
# global option `-d`. Using this should be the same as using `cd` and
|
|
28
|
+
# executing the command.
|
|
29
|
+
#
|
|
30
|
+
# @return [::String]
|
|
31
|
+
attr_reader :directory
|
|
32
|
+
|
|
33
|
+
# Defines and runs the command line interface.
|
|
34
|
+
#
|
|
35
|
+
# @see #call
|
|
36
|
+
# @return [void]
|
|
37
|
+
def self.call
|
|
38
|
+
new.call
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Defines and runs the command line interface.
|
|
42
|
+
#
|
|
43
|
+
# @see #program_information
|
|
44
|
+
# @see #configure_global_option
|
|
45
|
+
# @see #directory_global_option
|
|
46
|
+
# @see InitializeCommand.define
|
|
47
|
+
# @see BenchCommand.define
|
|
48
|
+
# @see BuildCommand.define
|
|
49
|
+
# @see ServeCommand.define
|
|
50
|
+
# @return [void]
|
|
51
|
+
def call
|
|
52
|
+
program_information
|
|
53
|
+
configure_global_option
|
|
54
|
+
directory_global_option
|
|
55
|
+
command(:initialize) { |c| InitializeCommand.define(self, c) }
|
|
56
|
+
command(:bench) { |c| BenchCommand.define(self, c) }
|
|
57
|
+
command(:build) { |c| BuildCommand.define(self, c) }
|
|
58
|
+
command(:serve) { |c| ServeCommand.define(self, c) }
|
|
59
|
+
alias_command(:init, :initialize)
|
|
60
|
+
default_command(:build)
|
|
61
|
+
run!
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# The program information. This is for use with Commander.
|
|
65
|
+
#
|
|
66
|
+
# @return [void]
|
|
67
|
+
def program_information
|
|
68
|
+
program :name, "Brandish"
|
|
69
|
+
program :version, Brandish::VERSION
|
|
70
|
+
program :help_formatter, :compact
|
|
71
|
+
program :help_paging, false
|
|
72
|
+
program :description, "A multi-format document generator."
|
|
73
|
+
program :help, "Author", "Jeremy Rodi <jeremy.rodi@medcat.me>"
|
|
74
|
+
program :help, "License", "MIT License Copyright (c) 2017 Jeremy Rodi"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Defines the config global option. This sets {#config_file} to its
|
|
78
|
+
# default file, and defines an option that can set it.
|
|
79
|
+
#
|
|
80
|
+
# @return [void]
|
|
81
|
+
def configure_global_option
|
|
82
|
+
@config_file = "brandish.config.rb"
|
|
83
|
+
global_option("--config FILE") { |f| @config_file = f }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Defines the directory global option. This sets {#directory} to its
|
|
87
|
+
# default value, and defines an option that can set it.
|
|
88
|
+
#
|
|
89
|
+
# @return [void]
|
|
90
|
+
def directory_global_option
|
|
91
|
+
@directory = Pathname.new(Dir.pwd)
|
|
92
|
+
global_option("--directory PATH") do |path|
|
|
93
|
+
@directory = Pathname.new(path).expand_path(Dir.pwd)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Options that are passed to the `progress` method provided by Commander.
|
|
98
|
+
# This makes it look "nice."
|
|
99
|
+
#
|
|
100
|
+
# @return [{::Symbol => ::String}]
|
|
101
|
+
PROGRESS_OPTIONS = {
|
|
102
|
+
title: " Building...", progress_str: "#", incomplete_str: " ",
|
|
103
|
+
format: ":title <:progress_bar> :percent_complete%",
|
|
104
|
+
complete_message: " Build complete!"
|
|
105
|
+
}.freeze
|
|
106
|
+
|
|
107
|
+
# The width of all of the set text items in the progress bar. This is
|
|
108
|
+
# used to dynamically determine the with of the progress bar later on.
|
|
109
|
+
#
|
|
110
|
+
# @return [::Numeric]
|
|
111
|
+
PROGRESS_WIDTH = " Building... < > 000% ".length
|
|
112
|
+
|
|
113
|
+
# Creates a progress bar on the terminal based off of the given array.
|
|
114
|
+
# This mostly passes everything on to the `progress` method provided by
|
|
115
|
+
# Commander, but with a few options added.
|
|
116
|
+
#
|
|
117
|
+
# @param array [::Array] The array of items that are being processed.
|
|
118
|
+
# @yield [item] Once for every item in the array. Once the block ends,
|
|
119
|
+
# the progress bar increments.
|
|
120
|
+
# @yieldparam item [::Object] One of the items in the array.
|
|
121
|
+
# @return [void]
|
|
122
|
+
def progress(array, &block)
|
|
123
|
+
# rubocop:disable Style/GlobalVars
|
|
124
|
+
width = $terminal.terminal_size[0] - PROGRESS_WIDTH
|
|
125
|
+
# rubocop:enable Style/GlobalVars
|
|
126
|
+
options = PROGRESS_OPTIONS.merge(width: width)
|
|
127
|
+
super(array, options, &block)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# The path to the configuration file. This is used for
|
|
131
|
+
# {#load_configuration_file!}.
|
|
132
|
+
#
|
|
133
|
+
# @return [::Pathname]
|
|
134
|
+
def config_file_path
|
|
135
|
+
@directory / @config_file
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# If the configuration isn't already loaded, load it; otherwise, just
|
|
139
|
+
# return the already loaded version of the configuration file.
|
|
140
|
+
#
|
|
141
|
+
# @return [Configure]
|
|
142
|
+
def load_configuration_file
|
|
143
|
+
Brandish.configuration || load_configuration_file!
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Forces the configuration file to be loaded, even if it already was;
|
|
147
|
+
# this first resets the configuration using {Brandish.reset_configuration},
|
|
148
|
+
# then it loads the {#config_file_path}. If no configuration was provided,
|
|
149
|
+
# it fails; if it didn't load properly, it fails.
|
|
150
|
+
#
|
|
151
|
+
# @raise [RuntimeError] If no configuration was provided, or if it didn't
|
|
152
|
+
# load properly.
|
|
153
|
+
# @return [Configure]
|
|
154
|
+
def load_configuration_file!
|
|
155
|
+
Brandish.reset_configuration
|
|
156
|
+
load config_file_path.to_s
|
|
157
|
+
fail "No configuration provided" unless Brandish.configuration
|
|
158
|
+
Brandish.configuration
|
|
159
|
+
rescue LoadError
|
|
160
|
+
fail "No configuration provided"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|