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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "brandish/processors/html/group"
|
|
5
|
+
require "brandish/processors/html/header"
|
|
6
|
+
require "brandish/processors/html/markup"
|
|
7
|
+
require "brandish/processors/html/output"
|
|
8
|
+
require "brandish/processors/html/style"
|
|
9
|
+
require "brandish/processors/html/script"
|
|
10
|
+
|
|
11
|
+
module Brandish
|
|
12
|
+
module Processors
|
|
13
|
+
# Processors for generating HTML output. This implements the {Common}
|
|
14
|
+
# processors.
|
|
15
|
+
module HTML
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "hanami/helpers/html_helper"
|
|
5
|
+
require "hanami/helpers/escape_helper"
|
|
6
|
+
|
|
7
|
+
module Brandish
|
|
8
|
+
module Processors
|
|
9
|
+
module HTML
|
|
10
|
+
# A "group." This is used for grouping together elements for styling,
|
|
11
|
+
# like the "div" element in HTML. This uses `div` as one of the
|
|
12
|
+
# element names, but that doesn't mean that it includes all of the same
|
|
13
|
+
# attributes. This accepts the `"class"`, `"id"`, and `"name"` headers.
|
|
14
|
+
#
|
|
15
|
+
# @see Common::Group
|
|
16
|
+
class Group < Common::Group
|
|
17
|
+
include Processor::Block
|
|
18
|
+
include Hanami::Helpers::HtmlHelper
|
|
19
|
+
include Hanami::Helpers::EscapeHelper
|
|
20
|
+
register %i(html group) => self
|
|
21
|
+
self.names = %i(group g div)
|
|
22
|
+
|
|
23
|
+
# Creates a div element with the proper class and id values. This
|
|
24
|
+
# currently ignores the name value.
|
|
25
|
+
#
|
|
26
|
+
# @return [::String]
|
|
27
|
+
def perform
|
|
28
|
+
html.div(raw(accepted_body), class: class_value, id: id_value).to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "hanami/helpers/html_helper"
|
|
5
|
+
|
|
6
|
+
module Brandish
|
|
7
|
+
module Processors
|
|
8
|
+
module HTML
|
|
9
|
+
# A processor that defines the `header` command. This creates a list
|
|
10
|
+
# internally of all of the headers in the document, to later be used to
|
|
11
|
+
# possibly create a table of contents, if needed.
|
|
12
|
+
#
|
|
13
|
+
# This takes no options.
|
|
14
|
+
#
|
|
15
|
+
# Pairs:
|
|
16
|
+
#
|
|
17
|
+
# - `"level"` - Optional. Defaults to `1`. The "level" of the header.
|
|
18
|
+
# This should be a value between 1 and 6.
|
|
19
|
+
# - `"value"` - Required. The name of the header.
|
|
20
|
+
# - `"id"` - Optional. The ID of the header. This is a unique value
|
|
21
|
+
# to reference to this header. If no value is given, it defaults
|
|
22
|
+
# to a modified `"value"`.
|
|
23
|
+
# - `"class"` - Optional. The class name of the header.
|
|
24
|
+
class Header < Processors::Common::Header
|
|
25
|
+
include Hanami::Helpers::HtmlHelper
|
|
26
|
+
register %i(html header) => self
|
|
27
|
+
pair :class
|
|
28
|
+
|
|
29
|
+
# The tags to use for each header level. This is just `h1` through
|
|
30
|
+
# `h6`.
|
|
31
|
+
#
|
|
32
|
+
# @return [::Symbol]
|
|
33
|
+
TAGS = %i(h1 h2 h3 h4 h5 h6).freeze
|
|
34
|
+
|
|
35
|
+
# Renders the proper HTML tag for the header, including the proper
|
|
36
|
+
# id, and an optional class value from the pairs.
|
|
37
|
+
#
|
|
38
|
+
# @return [::String]
|
|
39
|
+
def header_render
|
|
40
|
+
html.tag(TAGS.fetch(header_level - 1), header_value, id: header_id,
|
|
41
|
+
class: @pairs.fetch("class", "")).to_s
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "hanami/helpers/escape_helper"
|
|
5
|
+
|
|
6
|
+
module Brandish
|
|
7
|
+
module Processors
|
|
8
|
+
module HTML
|
|
9
|
+
# Markup support for the HTML format. For more information, and available
|
|
10
|
+
# options, see the {Processors::Common::Markup} processor.
|
|
11
|
+
#
|
|
12
|
+
# This markup processor provides the following engines:
|
|
13
|
+
#
|
|
14
|
+
# - `:kramdown` - A Markdown formatter. More information on this
|
|
15
|
+
# markup format can be found at <https://github.com/gettalong/kramdown>.
|
|
16
|
+
# Available options are: `:template`, `:auto_ids` (not recommended),
|
|
17
|
+
# `:auto_id_stripping` (not recommended), `:auto_id_prefix` (not
|
|
18
|
+
# recommended), `:parse_block_html`, `:parse_span_html`,
|
|
19
|
+
# `:html_to_native`, `:link_defs`, `:footnote_nr`, `:enable_coderay`,
|
|
20
|
+
# `:coderay_wrap`, `:coderay_line_numbers`,
|
|
21
|
+
# `:coderay_line_number_start`, `:coderay_tab_width`,
|
|
22
|
+
# `:coderay_bold_every`, `:coderay_css`, `:coderay_default_lang`,
|
|
23
|
+
# `:entity_output`, `:toc_levels` (not recommended), `:line_width`,
|
|
24
|
+
# `:latex_headers` (does nothing), `:smart_quotes`,
|
|
25
|
+
# `:remove_block_html_tags`, `:remove_span_html_tags`,
|
|
26
|
+
# `:header_offset`, `:hard_wrap`, `:syntax_highlighter`,
|
|
27
|
+
# `:syntax_highlighter_opts`, `:math_engine`, `:math_engine_opts`,
|
|
28
|
+
# `:footnote_backlink`, and `:gfm_quirks`. Requires the kramdown
|
|
29
|
+
# gem.
|
|
30
|
+
# - `:rdiscount` - A Markdown formatter. More information on this
|
|
31
|
+
# markup format can be found at <https://github.com/davidfstr/rdiscount>.
|
|
32
|
+
# The options for this engine are specified in an array, not a
|
|
33
|
+
# hash. Available options are: `:smart`, `:filter_styles`,
|
|
34
|
+
# `:filter_html`, `:fold_lines`, `:footnotes`, `:generate_toc` (not
|
|
35
|
+
# recommended), `:no_image`, `:no_links`, `:no_tables`, `:strict`,
|
|
36
|
+
# `:autolink`, `:safelink`, `:no_pseudo_protocals`, `:no_superscript`,
|
|
37
|
+
# and `:no_strikethrough`. Requires the rdiscount gem.
|
|
38
|
+
# - `:minidown` - A Markdown formatter. More information on this
|
|
39
|
+
# markup format can be found at <https://github.com/jjyr/minidown>.
|
|
40
|
+
# Available options are: `:code_block_handler`.
|
|
41
|
+
# - `:redcloth` - A Textile formatter. More information on this
|
|
42
|
+
# markup format can be found at <https://github.com/jgarber/redcloth>.
|
|
43
|
+
# Available options are: `:filter_html`, `:sanitize_html`,
|
|
44
|
+
# `:filter_styles`, `:filter_classes`, `:filter_ids`,
|
|
45
|
+
# `:hard_breaks` (deprecated, default), `:lite_mode`,
|
|
46
|
+
# and `:no_span_caps`.
|
|
47
|
+
# - `:redcarpet` - A Markdown formatter. More information on this
|
|
48
|
+
# markup format can be found at <https://github.com/vmg/redcarpet>.
|
|
49
|
+
# This is the preferred format for Brandish due to its integration.
|
|
50
|
+
# The options that are valid for this formatter can be found on
|
|
51
|
+
# {Brandish::Markup::Redcarpet::Format}.
|
|
52
|
+
# - `:creole` - A creole formatter. More information on this markup
|
|
53
|
+
# format can be found at <https://github.com/larsch/creole>.
|
|
54
|
+
# Available options are: `:allowed_schemes`, `:extensions`,
|
|
55
|
+
# and `:no_escape`.
|
|
56
|
+
# - `:sanitize` - A sanitizer, to remove non-whitelisted elements.
|
|
57
|
+
# More information on this can be found at <https://github.com/rgrove/sanitize>.
|
|
58
|
+
# The option can be a symbol or a hash; the hash is passed directly
|
|
59
|
+
# to sanitize. The symbol is mapped to one of the corresponding
|
|
60
|
+
# default configs. Symbol values are: `:restricted`, `:basic`,
|
|
61
|
+
# `:relaxed`, and `:basic`.
|
|
62
|
+
# - `:escape` - Escapes the content to prevent conflict with the
|
|
63
|
+
# resulting format.
|
|
64
|
+
#
|
|
65
|
+
# @note
|
|
66
|
+
# This class provides the `html:markup` processor.
|
|
67
|
+
class Markup < Processors::Common::Markup
|
|
68
|
+
include Hanami::Helpers::EscapeHelper
|
|
69
|
+
register %i(html markup) => self
|
|
70
|
+
|
|
71
|
+
engine(:kramdown, {}, nil, :markup_kramdown)
|
|
72
|
+
engine(:rdiscount, [:smart], nil, :markup_rdiscount)
|
|
73
|
+
engine(:minidown, {}, :initialize_minidown, :markup_minidown)
|
|
74
|
+
engine(:redcloth, [], nil, :markup_redcloth)
|
|
75
|
+
engine(:redcarpet, {}, :initialize_redcarpet, :markup_redcarpet)
|
|
76
|
+
engine(:creole, { extensions: true }, nil, :markup_creole)
|
|
77
|
+
engine(:sanitize, :relaxed, nil, :markup_sanitize)
|
|
78
|
+
engine(:escape, nil, nil, :markup_escape)
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def markup_kramdown(value, options)
|
|
83
|
+
Kramdown::Document.new(value, options).to_html
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def markup_rdiscount(value, options)
|
|
87
|
+
::RDiscount.new(value, *options).to_html
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def initialize_minidown
|
|
91
|
+
@parser = ::Minidown::Parser.new(engine_options)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def markup_minidown(value, _)
|
|
95
|
+
@parser.render(value)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def markup_redcloth(value, options)
|
|
99
|
+
::RedCloth.new(value, options).to_html
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def initialize_redcarpet
|
|
103
|
+
data = engine_options.merge(format: :html, context: @context)
|
|
104
|
+
@format = ::Brandish::Markup::Redcarpet::Format.new(data)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def markup_redcarpet(value, _options)
|
|
108
|
+
@format.render(value)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def markup_creole(value, options)
|
|
112
|
+
::Creole::Parser.new(value, options).to_html
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def initialize_sanitize
|
|
116
|
+
return unless engine_options.is_a?(::Symbol)
|
|
117
|
+
@_engine_options =
|
|
118
|
+
::Sanitize::Config.const_get(engine_options.to_s.upcase)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def markup_sanitize(value, options)
|
|
122
|
+
::Sanitize.fragment(value, options)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def markup_escape(value, _options)
|
|
126
|
+
h(value)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "mustache"
|
|
5
|
+
require "brandish/processors/html/output/document"
|
|
6
|
+
|
|
7
|
+
module Brandish
|
|
8
|
+
module Processors
|
|
9
|
+
module HTML
|
|
10
|
+
# Outputs the result of processing the document. Without this processor,
|
|
11
|
+
# the document is not output, and most other processors have no effect.
|
|
12
|
+
#
|
|
13
|
+
# Options:
|
|
14
|
+
#
|
|
15
|
+
# - `:template` - Optional. The name of the template to use. This
|
|
16
|
+
# defaults to the format used.
|
|
17
|
+
# - `:path` - Optional. The full path, including the file name,
|
|
18
|
+
# to output the file. This overwrites `:directory` and `:file`.
|
|
19
|
+
# Defaults to `:directory`/`:file`.
|
|
20
|
+
# - `:directory` - Optional. The directory to the file to output
|
|
21
|
+
# the file. Overwritten by `:path`. Defaults to the output path
|
|
22
|
+
# of the project.
|
|
23
|
+
# - `:file` - Optional. The name of the file to output to. Overwritten
|
|
24
|
+
# by `:path`. Defaults to the name of the entry file, with the
|
|
25
|
+
# extension substituted by `".html"`.
|
|
26
|
+
#
|
|
27
|
+
# @see Common::Output
|
|
28
|
+
class Output < Common::Output
|
|
29
|
+
register %i(html output) => self
|
|
30
|
+
|
|
31
|
+
# Sets up the output processor. This creates a {Document} and puts
|
|
32
|
+
# it on the `:document` context option.
|
|
33
|
+
#
|
|
34
|
+
# @see Common::Output#setup
|
|
35
|
+
# @return [void]
|
|
36
|
+
def setup
|
|
37
|
+
super
|
|
38
|
+
|
|
39
|
+
@document = @context[:document] = Document.new
|
|
40
|
+
@document.title = @context.configure.root.basename.to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def find_path
|
|
46
|
+
@options.fetch(:path) do
|
|
47
|
+
directory = @options.fetch(:directory, ".")
|
|
48
|
+
file = @options.fetch(:file) do
|
|
49
|
+
::Pathname.new(@context.form.entry).sub_ext(".html")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
directory.expand_path(@context.configure.output) / file
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def template_data
|
|
57
|
+
@document.data.merge("content" => @root.flatten)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Output < Common::Output
|
|
8
|
+
# A "document." This contains meta information for the document,
|
|
9
|
+
# such as the title, author, description, styles, and scripts that
|
|
10
|
+
# are used to set up the HTML document.
|
|
11
|
+
#
|
|
12
|
+
# @api private
|
|
13
|
+
class Document
|
|
14
|
+
# The title of the document. This is used for the `<title>` tag.
|
|
15
|
+
#
|
|
16
|
+
# @return [::String, nil]
|
|
17
|
+
attr_accessor :title
|
|
18
|
+
|
|
19
|
+
# The author for the document. This is used for a `<meta>` tag.
|
|
20
|
+
#
|
|
21
|
+
# @return [::String, nil]
|
|
22
|
+
attr_accessor :author
|
|
23
|
+
|
|
24
|
+
# The description of the document. This is used for a `<meta>` tag.
|
|
25
|
+
#
|
|
26
|
+
# @return [::String, nil]
|
|
27
|
+
attr_accessor :description
|
|
28
|
+
|
|
29
|
+
# Initialize the document.
|
|
30
|
+
def initialize
|
|
31
|
+
@title = ""
|
|
32
|
+
@author = ""
|
|
33
|
+
@description = ""
|
|
34
|
+
@styles = []
|
|
35
|
+
@scripts = []
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Adds a given style with the given type. The type is the kind of
|
|
39
|
+
# style it is; this should be either one of `:inline` or `:linked`.
|
|
40
|
+
#
|
|
41
|
+
# @param type [::Symbol] The style type.
|
|
42
|
+
# @param content [::String] The contents of the style. For an
|
|
43
|
+
# inline style, this is the stylesheet itself; for a linked
|
|
44
|
+
# style, this is the link to the stylesheet.
|
|
45
|
+
# @return [self]
|
|
46
|
+
def add_style(type, content)
|
|
47
|
+
inline = type == :inline
|
|
48
|
+
linked = type == :linked
|
|
49
|
+
|
|
50
|
+
@styles << {
|
|
51
|
+
"inline?" => inline,
|
|
52
|
+
"linked?" => linked,
|
|
53
|
+
"content" => content.to_s
|
|
54
|
+
}
|
|
55
|
+
self
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Adds a given script with the given type. The type of the kind of
|
|
59
|
+
# script it is; this should be either one of `:inline` or `:linked`.
|
|
60
|
+
#
|
|
61
|
+
# @param type [::Symbol] The style type.
|
|
62
|
+
# @param content [::String] The contents of the script. For an
|
|
63
|
+
# inline style, this is the script it self; for a linked script,
|
|
64
|
+
# this is the link to the script.
|
|
65
|
+
# @return [self]
|
|
66
|
+
def add_script(type, content)
|
|
67
|
+
inline = type == :inline
|
|
68
|
+
linked = type == :linked
|
|
69
|
+
|
|
70
|
+
@scripts << {
|
|
71
|
+
"inline?" => inline,
|
|
72
|
+
"linked?" => linked,
|
|
73
|
+
"content" => content.to_s
|
|
74
|
+
}
|
|
75
|
+
self
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Adds an inline style.
|
|
79
|
+
#
|
|
80
|
+
# @see #add_style
|
|
81
|
+
# @param content [::String] The stylesheet itself.
|
|
82
|
+
# @return (see #add_style)
|
|
83
|
+
def add_inline_style(content)
|
|
84
|
+
add_style(:inline, content)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Adds an linked style.
|
|
88
|
+
#
|
|
89
|
+
# @see #add_style
|
|
90
|
+
# @param content [::String] The link to the stylesheet.
|
|
91
|
+
# @return (see #add_style)
|
|
92
|
+
def add_linked_style(content)
|
|
93
|
+
add_style(:linked, URI.escape(content.to_s))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Adds an inline script.
|
|
97
|
+
#
|
|
98
|
+
# @see #add_script
|
|
99
|
+
# @param content [::String] The script itself.
|
|
100
|
+
# @return (see #add_script)
|
|
101
|
+
def add_inline_script(content)
|
|
102
|
+
add_script(:inline, content)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Adds an linked script.
|
|
106
|
+
#
|
|
107
|
+
# @see #add_script
|
|
108
|
+
# @param content [::String] The link to the script.
|
|
109
|
+
# @return (see #add_script)
|
|
110
|
+
def add_linked_script(content)
|
|
111
|
+
add_script(:linked, URI.escape(content.to_s))
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The data from this document. This is used to pass all of the
|
|
115
|
+
# proper information to the templating library.
|
|
116
|
+
#
|
|
117
|
+
# @return [::Object]
|
|
118
|
+
def data
|
|
119
|
+
{ "title" => @title, "author" => @author,
|
|
120
|
+
"description" => @description,
|
|
121
|
+
"styles" => @styles, "scripts" => @scripts }.freeze
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "brandish/processors/html/script/babel"
|
|
5
|
+
require "brandish/processors/html/script/coffee"
|
|
6
|
+
require "brandish/processors/html/script/vanilla"
|
|
7
|
+
|
|
8
|
+
module Brandish
|
|
9
|
+
module Processors
|
|
10
|
+
module HTML
|
|
11
|
+
# A script asset. This is a JavaScript asset.
|
|
12
|
+
#
|
|
13
|
+
# Engines:
|
|
14
|
+
#
|
|
15
|
+
# - `"babel"`, `"babel-file"` - A command. This takes the contents
|
|
16
|
+
# of the resolved file, transpiles it, and outputs it into
|
|
17
|
+
# the output path, given by `#load_file_paths`.
|
|
18
|
+
# - `"babel-inline"` - A block. Similar to `"babel"`; however, it
|
|
19
|
+
# takes the block, uses {Parser::Node::Root#flatten} on it,
|
|
20
|
+
# transpiles the result, and adds that as an inline script.
|
|
21
|
+
# - `"coffee"`, `"coffee-file"` - A command. This takes the contents
|
|
22
|
+
# of the resolved file, transpiles it, and outputs it into
|
|
23
|
+
# the output path, given by `#load_file_paths`.
|
|
24
|
+
# - `"coffee-inline"` - A block. Similar to `"coffee"`; however, it
|
|
25
|
+
# takes the block, uses {Parser::Node::Root#flatten} on it,
|
|
26
|
+
# transpiles the result, and adds that as an inline script.
|
|
27
|
+
# - `"file"` - A command. Takes a file, and copies it over to the
|
|
28
|
+
# destination, based on the values given in `#load_file_paths`.
|
|
29
|
+
# - `"remote"`, `"remote-file"` - A command. Takes a URI (supports
|
|
30
|
+
# `http`, `https`, and `ftp`), and outputs the directory into the
|
|
31
|
+
# `"output"` pair (or a uri path assumed from the URI).
|
|
32
|
+
# - `"inline"` - A block. This performs {Parser::Node::Root#flatten}
|
|
33
|
+
# on the body, and pushes the result as an inline style.
|
|
34
|
+
# - `"remote-inline"` - A command. Similar to `"remote"`; however,
|
|
35
|
+
# this takes the remote styles as an inline style.
|
|
36
|
+
#
|
|
37
|
+
# Pairs:
|
|
38
|
+
#
|
|
39
|
+
# - `"src"`, `"file"`, `"name"`, or `"link"` - Required. At least one
|
|
40
|
+
# of these options are required. They all perform the same function.
|
|
41
|
+
# This defines the name or path of the asset to add or process.
|
|
42
|
+
# - `"type"` - Required. The type of the asset to process. This defines
|
|
43
|
+
# how the asset is handled.
|
|
44
|
+
class Script < Common::Asset
|
|
45
|
+
register %i(html script) => self
|
|
46
|
+
self.names = %i(script scripting)
|
|
47
|
+
|
|
48
|
+
include Script::Babel
|
|
49
|
+
include Script::Coffee
|
|
50
|
+
include Script::Vanilla
|
|
51
|
+
|
|
52
|
+
# (see Common::Asset::Paths#asset_kind_path)
|
|
53
|
+
def asset_kind_path
|
|
54
|
+
"assets/scripts"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# (see Common::Asset::Paths#asset_kind_extension)
|
|
58
|
+
def asset_kind_extension
|
|
59
|
+
".js"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|