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,48 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Script < Common::Asset
|
|
8
|
+
# A set of scripting engines that use the Babel transpiler.
|
|
9
|
+
#
|
|
10
|
+
# Engines:
|
|
11
|
+
#
|
|
12
|
+
# - `"babel"`, `"babel-file"` - A command. This takes the contents
|
|
13
|
+
# of the resolved file, transpiles it, and outputs it into
|
|
14
|
+
# the output path, given by `#load_file_paths`.
|
|
15
|
+
# - `"babel-inline"` - A block. Similar to `"babel"`; however, it
|
|
16
|
+
# takes the block, uses {Parser::Node::Root#flatten} on it,
|
|
17
|
+
# transpiles the result, and adds that as an inline script.
|
|
18
|
+
#
|
|
19
|
+
# @note
|
|
20
|
+
# The libraries that these engines depend on are not required in
|
|
21
|
+
# by default; if any of these engines are used, the requisite
|
|
22
|
+
# libraries would have to be required by the `brandish.config.rb`
|
|
23
|
+
# file.
|
|
24
|
+
module Babel
|
|
25
|
+
Script.engine "babel", :command, :script_babel_file
|
|
26
|
+
Script.engine "babel-file", :command, :script_babel_file
|
|
27
|
+
Script.engine "babel-inline", :block, :script_babel_inline
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def script_babel_inline
|
|
32
|
+
parsed = ::Babel::Transpiler.transform(@body.flatten)
|
|
33
|
+
@context[:document].add_inline_script(parsed["code"])
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def script_babel_file
|
|
37
|
+
paths = load_file_paths
|
|
38
|
+
paths[:out].dirname.mkpath
|
|
39
|
+
parsed = ::Babel::Transpiler.transform(paths[:file].read)
|
|
40
|
+
paths[:out].write(parsed["code"])
|
|
41
|
+
|
|
42
|
+
@context[:document].add_linked_script(paths[:src])
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Script < Common::Asset
|
|
8
|
+
# A set of scripting engines that use the Coffee transpiler.
|
|
9
|
+
#
|
|
10
|
+
# Engines:
|
|
11
|
+
#
|
|
12
|
+
# - `"coffee"`, `"coffee-file"` - A command. This takes the contents
|
|
13
|
+
# of the resolved file, transpiles it, and outputs it into
|
|
14
|
+
# the output path, given by `#load_file_paths`.
|
|
15
|
+
# - `"coffee-inline"` - A block. Similar to `"coffee"`; however, it
|
|
16
|
+
# takes the block, uses {Parser::Node::Root#flatten} on it,
|
|
17
|
+
# transpiles the result, and adds that as an inline script.
|
|
18
|
+
#
|
|
19
|
+
# @note
|
|
20
|
+
# The libraries that these engines depend on are not required in
|
|
21
|
+
# by default; if any of these engines are used, the requisite
|
|
22
|
+
# libraries would have to be required by the `brandish.config.rb`
|
|
23
|
+
# file.
|
|
24
|
+
module Coffee
|
|
25
|
+
Script.engine "coffee", :command, :script_coffee_file
|
|
26
|
+
Script.engine "coffee-file", :command, :script_coffee_file
|
|
27
|
+
Script.engine "coffee-inline", :block, :script_coffee_inline
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def script_coffee_inline
|
|
32
|
+
parsed = ::CoffeeScript.compile(@body.flatten)
|
|
33
|
+
@context[:document].add_inline_script(parsed)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def script_coffee_file
|
|
37
|
+
paths = load_file_paths
|
|
38
|
+
paths[:out].dirname.mkpath
|
|
39
|
+
paths[:out].write(::CoffeeScript.compile(paths[:file].read))
|
|
40
|
+
|
|
41
|
+
@context[:document].add_linked_script(paths[:src])
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Script < Common::Asset
|
|
8
|
+
# "Vanilla" scripting engines. This just performs copying, and
|
|
9
|
+
# does not modify the contents of the styles at all.
|
|
10
|
+
#
|
|
11
|
+
# Engines:
|
|
12
|
+
#
|
|
13
|
+
# - `"file"` - A command. Takes a file, and copies it over to the
|
|
14
|
+
# destination, based on the values given in `#load_file_paths`.
|
|
15
|
+
# - `"remote"`, `"remote-file"` - A command. Takes a URI (supports
|
|
16
|
+
# `http`, `https`, and `ftp`), and outputs the directory into the
|
|
17
|
+
# `"output"` pair (or a uri path assumed from the URI).
|
|
18
|
+
# - `"inline"` - A block. This performs {Parser::Node::Root#flatten}
|
|
19
|
+
# on the body, and pushes the result as an inline style.
|
|
20
|
+
# - `"remote-inline"` - A command. Similar to `"remote"`; however,
|
|
21
|
+
# this takes the remote styles as an inline style.
|
|
22
|
+
module Vanilla
|
|
23
|
+
Script.engine "inline", :block, :script_inline
|
|
24
|
+
Script.engine "file", :command, :script_file
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def script_inline
|
|
29
|
+
@context[:document].add_inline_script(@body.flatten)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def script_file
|
|
33
|
+
paths = load_file_paths
|
|
34
|
+
paths[:out].dirname.mkpath
|
|
35
|
+
src, dest = paths[:file].open("rb"), paths[:out].open("wb")
|
|
36
|
+
::IO.copy_stream(src, dest)
|
|
37
|
+
[src, dest].each(&:close)
|
|
38
|
+
|
|
39
|
+
@context[:document].add_linked_script(paths[:src])
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "brandish/processors/html/style/highlight"
|
|
5
|
+
require "brandish/processors/html/style/sass"
|
|
6
|
+
require "brandish/processors/html/style/vanilla"
|
|
7
|
+
|
|
8
|
+
module Brandish
|
|
9
|
+
module Processors
|
|
10
|
+
module HTML
|
|
11
|
+
# A Style asset. This is a CSS asset.
|
|
12
|
+
#
|
|
13
|
+
# Engines:
|
|
14
|
+
#
|
|
15
|
+
# - `"highlight-rouge"`, `"highlight-rouge-file"` - A command.
|
|
16
|
+
# Retrieves the given theme from the Rouge library, and outputs it
|
|
17
|
+
# to the `"output"` pair (or `"highlight/rouge/<theme>.css"` by
|
|
18
|
+
# default).
|
|
19
|
+
# - `"highlight-pygments", `"highlight-pygments-file"` - A command.
|
|
20
|
+
# Retrieves the given theme from the Pygments library, and outputs
|
|
21
|
+
# it to the `"output"` pair (or `"highlight/pygments/<theme>.css"`
|
|
22
|
+
# by default).
|
|
23
|
+
# - `"highlight-rouge-inline"` - A command. Retrieves the given theme
|
|
24
|
+
# from the Rouge library, and uses it like an inline style.
|
|
25
|
+
# - `"highlight-pygments-inline"` - A command. Retrieves the given
|
|
26
|
+
# theme from the pygments library, and uses it like an inline
|
|
27
|
+
# style.
|
|
28
|
+
# - `"sass"`, `"sass-file"`, `"scss"`, `"scss-file"` - A command.
|
|
29
|
+
# These take a file and processes it, and outputs it to the output
|
|
30
|
+
# path given by `#load_file_paths`. There is no difference
|
|
31
|
+
# between any of these engine types - the engine assumes the actual
|
|
32
|
+
# syntax of the file from the file extension.
|
|
33
|
+
# - `"sass-inline"` - A block. This takes the block's contents,
|
|
34
|
+
# performs {Parser::Node::Root#flatten} on it, and processes the
|
|
35
|
+
# content as Sass. This is then included as an inline stylesheet.
|
|
36
|
+
# - `"scss-inline" - A block. Similar to `"sass-inline"`, except it
|
|
37
|
+
# processes the content as SCSS.
|
|
38
|
+
# - `"file"` - A command. Takes a file, and copies it over to the
|
|
39
|
+
# destination, based on the values given in `#load_file_paths`.
|
|
40
|
+
# - `"remote"`, `"remote-file"` - A command. Takes a URI (supports
|
|
41
|
+
# `http`, `https`, and `ftp`), and outputs the directory into the
|
|
42
|
+
# `"output"` pair (or a uri path assumed from the URI).
|
|
43
|
+
# - `"inline"` - A block. This performs {Parser::Node::Root#flatten}
|
|
44
|
+
# on the body, and pushes the result as an inline style.
|
|
45
|
+
# - `"remote-inline"` - A command. Similar to `"remote"`; however,
|
|
46
|
+
# this takes the remote styles as an inline style.
|
|
47
|
+
#
|
|
48
|
+
# Pairs:
|
|
49
|
+
#
|
|
50
|
+
# - `"src"`, `"file"`, `"name"`, or `"link"` - Required. At least one
|
|
51
|
+
# of these options are required. They all perform the same function.
|
|
52
|
+
# This defines the name or path of the asset to add or process.
|
|
53
|
+
# - `"type"` - Required. The type of the asset to process. This defines
|
|
54
|
+
# how the asset is handled.
|
|
55
|
+
# - `"theme"` - Required (for `highlight-*` engines only). The theme
|
|
56
|
+
# to find for styling.
|
|
57
|
+
# - `"scope"` - Required (for `highlight-*` engines only). The CSS
|
|
58
|
+
# scope for styling.
|
|
59
|
+
# - `"output"` - Optional (for `highlight-*` engines or for
|
|
60
|
+
# `"remote"`/`"remote-file"` that output to a file only). The output
|
|
61
|
+
# path for the CSS file.
|
|
62
|
+
class Style < Common::Asset
|
|
63
|
+
register %i(html style) => self
|
|
64
|
+
self.names = %i(style styling)
|
|
65
|
+
|
|
66
|
+
include Style::Highlight
|
|
67
|
+
include Style::Sass
|
|
68
|
+
include Style::Vanilla
|
|
69
|
+
|
|
70
|
+
# (see Common::Asset::Paths#asset_kind_path)
|
|
71
|
+
def asset_kind_path
|
|
72
|
+
"assets/styles"
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# (see Common::Asset::Paths#asset_kind_extension)
|
|
76
|
+
def asset_kind_extension
|
|
77
|
+
".css"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Style < Common::Asset
|
|
8
|
+
# A Style engine for highlighting libraries. This supports
|
|
9
|
+
# Rouge and Pygments.
|
|
10
|
+
#
|
|
11
|
+
# Engines:
|
|
12
|
+
#
|
|
13
|
+
# - `"highlight-rouge"`, `"highlight-rouge-file"` - A command.
|
|
14
|
+
# Retrieves the given theme from the Rouge library, and outputs it
|
|
15
|
+
# to the `"output"` pair (or `"highlight/rouge/<theme>.css"` by
|
|
16
|
+
# default).
|
|
17
|
+
# - `"highlight-pygments", `"highlight-pygments-file"` - A command.
|
|
18
|
+
# Retrieves the given theme from the Pygments library, and outputs
|
|
19
|
+
# it to the `"output"` pair (or `"highlight/pygments/<theme>.css"`
|
|
20
|
+
# by default).
|
|
21
|
+
# - `"highlight-rouge-inline"` - A command. Retrieves the given theme
|
|
22
|
+
# from the Rouge library, and uses it like an inline style.
|
|
23
|
+
# - `"highlight-pygments-inline"` - A command. Retrieves the given
|
|
24
|
+
# theme from the pygments library, and uses it like an inline
|
|
25
|
+
# style.
|
|
26
|
+
#
|
|
27
|
+
# @note
|
|
28
|
+
# The libraries that these engines depend on are not required in
|
|
29
|
+
# by default; if any of these engines are used, the requisite
|
|
30
|
+
# libraries would have to be required by the `brandish.config.rb`
|
|
31
|
+
# file.
|
|
32
|
+
module Highlight
|
|
33
|
+
Style.engine "highlight-rouge", :command, :style_highlight_rouge
|
|
34
|
+
Style.engine "highlight-pygments", :command, :style_highlight_pygments
|
|
35
|
+
Style.engine "highlight-rouge-file", :command, :style_highlight_rouge
|
|
36
|
+
Style.engine "highlight-pygments-file", :command, :style_highlight_pygments
|
|
37
|
+
Style.engine "highlight-rouge-inline", :command, :style_highlight_rouge_inline
|
|
38
|
+
Style.engine "highlight-pygments-inline", :command, :style_highlight_pygments_inline
|
|
39
|
+
Style.pair :theme, :scope, :output
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def highlight_theme
|
|
44
|
+
@pairs.fetch("theme")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def highlight_rouge_value
|
|
48
|
+
scope = @pairs.fetch("scope", ".highlight")
|
|
49
|
+
options = { scope: scope }
|
|
50
|
+
::Rouge::Theme.find(highlight_theme).render(options)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def highlight_pygments_value
|
|
54
|
+
scope = @pairs.fetch("scope", ".highlight")
|
|
55
|
+
::Pygments.css(scope, style: highlight_theme)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def style_highlight_rouge
|
|
59
|
+
file = @pairs.fetch("output", "highlight/rouge/#{highlight_theme}.css")
|
|
60
|
+
output_path = output_styles_path / file
|
|
61
|
+
output_path.dirname.mkpath
|
|
62
|
+
link_path = output_path.relative_path_from(@context.configure.output)
|
|
63
|
+
output_path.write(highlight_rouge_value)
|
|
64
|
+
|
|
65
|
+
@context[:document].add_linked_style(link_path)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def style_highlight_pygments
|
|
69
|
+
file = @pairs.fetch("output", "highlight/pygments/#{highlight_theme}.css")
|
|
70
|
+
output_path = output_styles_path / file
|
|
71
|
+
output_path.dirname.mkpath
|
|
72
|
+
link_path = output_path.relative_path_from(@context.configure.output)
|
|
73
|
+
output_path.write(highlight_pygments_value)
|
|
74
|
+
|
|
75
|
+
@context[:document].add_linked_style(link_path)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def style_highlight_rouge_inline
|
|
79
|
+
@context[:document].add_inline_style(highlight_rouge_value)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def style_highlight_pygments_inline
|
|
83
|
+
@context[:document].add_inline_style(highlight_pygments_value)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Style < Common::Asset
|
|
8
|
+
# A set of styling engines that provide access to Sass/SCSS.
|
|
9
|
+
#
|
|
10
|
+
# Engines:
|
|
11
|
+
#
|
|
12
|
+
# - `"sass"`, `"sass-file"`, `"scss"`, `"scss-file"` - A command.
|
|
13
|
+
# These take a file and processes it, and outputs it to the output
|
|
14
|
+
# path given by `#load_file_paths`. There is no difference
|
|
15
|
+
# between any of these engine types - the engine assumes the actual
|
|
16
|
+
# syntax of the file from the file extension.
|
|
17
|
+
# - `"sass-inline"` - A block. This takes the block's contents,
|
|
18
|
+
# performs {Parser::Node::Root#flatten} on it, and processes the
|
|
19
|
+
# content as Sass. This is then included as an inline stylesheet.
|
|
20
|
+
# - `"scss-inline" - A block. Similar to `"sass-inline"`, except it
|
|
21
|
+
# processes the content as SCSS.
|
|
22
|
+
#
|
|
23
|
+
# @note
|
|
24
|
+
# The libraries that these engines depend on are not required in
|
|
25
|
+
# by default; if any of these engines are used, the requisite
|
|
26
|
+
# libraries would have to be required by the `brandish.config.rb`
|
|
27
|
+
# file.
|
|
28
|
+
module Sass
|
|
29
|
+
Style.engine "sass", :command, :style_file_sass
|
|
30
|
+
Style.engine "scss", :command, :style_file_sass
|
|
31
|
+
Style.engine "sass-file", :command, :style_file_sass
|
|
32
|
+
Style.engine "scss-file", :command, :style_file_sass
|
|
33
|
+
Style.engine "sass-inline", :block, :style_inline_sass
|
|
34
|
+
Style.engine "scss-inline", :block, :style_inline_scss
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def style_file_sass
|
|
39
|
+
paths = load_file_paths
|
|
40
|
+
paths[:out].dirname.mkpath
|
|
41
|
+
dest = paths[:out].open("wb")
|
|
42
|
+
sass_options = { load_paths: style_load_paths.to_a }
|
|
43
|
+
engine = ::Sass::Engine.for_file(paths[:file].to_s, sass_options)
|
|
44
|
+
output = engine.render
|
|
45
|
+
dest.write(output)
|
|
46
|
+
dest.close
|
|
47
|
+
|
|
48
|
+
@context[:document].add_linked_style(paths[:src])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def style_inline_scss
|
|
52
|
+
style_inline_sass(:scss)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def style_inline_sass(syntax = :sass)
|
|
56
|
+
sass_options = { syntax: syntax, load_paths: style_load_paths.to_a }
|
|
57
|
+
engine = ::Sass::Engine.new(@body.flatten, sass_options)
|
|
58
|
+
@context[:document].add_inline_style(engine.render)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Brandish
|
|
5
|
+
module Processors
|
|
6
|
+
module HTML
|
|
7
|
+
class Style < Common::Asset
|
|
8
|
+
# "Vanilla" stylesheet engines. This just performs copying, and
|
|
9
|
+
# does not modify the contents of the styles at all.
|
|
10
|
+
#
|
|
11
|
+
# Engines:
|
|
12
|
+
#
|
|
13
|
+
# - `"file"` - A command. Takes a file, and copies it over to the
|
|
14
|
+
# destination, based on the values given in `#load_file_paths`.
|
|
15
|
+
# - `"remote"`, `"remote-file"` - A command. Takes a URI (supports
|
|
16
|
+
# `http`, `https`, and `ftp`), and outputs the directory into the
|
|
17
|
+
# `"output"` pair (or a uri path assumed from the URI).
|
|
18
|
+
# - `"inline"` - A block. This performs {Parser::Node::Root#flatten}
|
|
19
|
+
# on the body, and pushes the result as an inline style.
|
|
20
|
+
# - `"remote-inline"` - A command. Similar to `"remote"`; however,
|
|
21
|
+
# this takes the remote styles as an inline style.
|
|
22
|
+
module Vanilla
|
|
23
|
+
Style.engine "file", :command, :style_file
|
|
24
|
+
Style.engine "remote", :command, :style_file_remote
|
|
25
|
+
Style.engine "inline", :block, :style_inline
|
|
26
|
+
Style.engine "remote-file", :command, :style_file_remote
|
|
27
|
+
Style.engine "remote-inline", :command, :style_inline_remote
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def style_inline_remote
|
|
32
|
+
uri = URI(load_style_file)
|
|
33
|
+
file = open(uri)
|
|
34
|
+
content = file.read
|
|
35
|
+
file.close
|
|
36
|
+
|
|
37
|
+
@context[:document].add_inline_style(content)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def style_file_remote
|
|
41
|
+
uri = URI(load_style_file)
|
|
42
|
+
file = open(uri)
|
|
43
|
+
asset_path = @pairs.fetch("output") { uri_path(uri) }
|
|
44
|
+
output_path = output_styles_path / asset_path
|
|
45
|
+
output_path.dirname.mkpath
|
|
46
|
+
link_path = output_path.relative_path_from(@context.configure.output)
|
|
47
|
+
output = output_path.open("wb")
|
|
48
|
+
::IO.copy_stream(file, output)
|
|
49
|
+
[file, output].each(&:close)
|
|
50
|
+
|
|
51
|
+
@context[:document].add_linked_style(link_path)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def style_inline
|
|
55
|
+
@context[:document].add_inline_style(@body.flatten)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def style_file
|
|
59
|
+
paths = load_file_paths
|
|
60
|
+
paths[:out].dirname.mkpath
|
|
61
|
+
src, dest = paths[:file].open("rb"), paths[:out].open("wb")
|
|
62
|
+
::IO.copy_stream(src, dest)
|
|
63
|
+
[src, dest].each(&:close)
|
|
64
|
+
|
|
65
|
+
@context[:document].add_linked_style(paths[:src])
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|