sass-embedded 0.5.0 → 0.6.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 +4 -4
- data/README.md +26 -0
- data/ext/extconf.rb +5 -5
- data/lib/sass.rb +22 -14
- data/lib/sass/embedded.rb +38 -36
- data/lib/sass/error.rb +8 -6
- data/lib/sass/info.rb +1 -1
- data/lib/sass/observer.rb +1 -2
- data/lib/sass/result.rb +30 -0
- data/lib/sass/struct.rb +20 -0
- data/lib/sass/transport.rb +1 -1
- data/lib/sass/util.rb +1 -1
- data/lib/sass/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8c00ba9bcce40d392862171f66b9ff3ef2ce1ef13e0a9d30a8541bc93804f6e
|
|
4
|
+
data.tar.gz: 9d4ccb5ab536b1f6a76a0e350a1244e00059d42db1ce666e5f7b19a84343424c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c6e542f29de342a3e9358136d3dda10be13d74c44c1a0e86be21f22a96997835a192aaf041d4a16d4092317de272d8be5589ad9075504057c9dbd7992be8b39
|
|
7
|
+
data.tar.gz: c05f1f8cd413387803ee9078fbb6670f21fc24ddde8b2661f64b495b7418ebea1488b496d98bcad9ebedd6e4f04532441652bf3b8aa2f4587a3780df548c0318
|
data/README.md
CHANGED
|
@@ -6,6 +6,12 @@ This is a Ruby library that implements the host side of the [Embedded Sass proto
|
|
|
6
6
|
|
|
7
7
|
It exposes a Ruby API for Sass that's backed by a native [Dart Sass](https://sass-lang.com/dart-sass) executable.
|
|
8
8
|
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
``` sh
|
|
12
|
+
gem install sass-embedded
|
|
13
|
+
```
|
|
14
|
+
|
|
9
15
|
## Usage
|
|
10
16
|
|
|
11
17
|
``` ruby
|
|
@@ -14,6 +20,26 @@ require "sass"
|
|
|
14
20
|
Sass.render(file: "style.scss")
|
|
15
21
|
```
|
|
16
22
|
|
|
23
|
+
## Options
|
|
24
|
+
|
|
25
|
+
`Sass.render()` support the following options:
|
|
26
|
+
|
|
27
|
+
- [`data`](https://sass-lang.com/documentation/js-api#data)
|
|
28
|
+
- [`file`](https://sass-lang.com/documentation/js-api#file)
|
|
29
|
+
- [`indented_syntax`](https://sass-lang.com/documentation/js-api#indentedsyntax)
|
|
30
|
+
- [`include_paths`](https://sass-lang.com/documentation/js-api#includepaths)
|
|
31
|
+
- [`output_style`](https://sass-lang.com/documentation/js-api#outputstyle)
|
|
32
|
+
- [`indent_type`](https://sass-lang.com/documentation/js-api#indenttype)
|
|
33
|
+
- [`indent_width`](https://sass-lang.com/documentation/js-api#indentwidth)
|
|
34
|
+
- [`linefeed`](https://sass-lang.com/documentation/js-api#linefeed)
|
|
35
|
+
- [`source_map`](https://sass-lang.com/documentation/js-api#sourcemap)
|
|
36
|
+
- [`out_file`](https://sass-lang.com/documentation/js-api#outfile)
|
|
37
|
+
- [`omit_source_map_url`](https://sass-lang.com/documentation/js-api#omitsourcemapurl)
|
|
38
|
+
- [`source_map_embed`](https://sass-lang.com/documentation/js-api#sourcemapembed)
|
|
39
|
+
- [`source_map_root`](https://sass-lang.com/documentation/js-api#sourcemaproot)
|
|
40
|
+
- [`functions`](https://sass-lang.com/documentation/js-api#functions)
|
|
41
|
+
- [`importer`](https://sass-lang.com/documentation/js-api#importer)
|
|
42
|
+
|
|
17
43
|
---
|
|
18
44
|
|
|
19
45
|
Disclaimer: this is not an official Google product.
|
data/ext/extconf.rb
CHANGED
|
@@ -8,9 +8,9 @@ require 'fileutils'
|
|
|
8
8
|
require_relative '../lib/sass/platform'
|
|
9
9
|
|
|
10
10
|
module Sass
|
|
11
|
-
# The dependency downloader. This
|
|
12
|
-
#
|
|
13
|
-
# dependencies. By default it
|
|
11
|
+
# The dependency downloader. This downloads all the dependencies during gem
|
|
12
|
+
# installation. The companion Makefile then unpacks all downloaded
|
|
13
|
+
# dependencies. By default it downloads the latest release of each
|
|
14
14
|
# dependency from GitHub releases.
|
|
15
15
|
#
|
|
16
16
|
# It is possible to specify an alternative source or version of each
|
|
@@ -18,9 +18,9 @@ module Sass
|
|
|
18
18
|
#
|
|
19
19
|
# @example
|
|
20
20
|
# gem install sass-embedded -- \
|
|
21
|
-
# --with-protoc=file:///path/to/protoc-*.zip
|
|
21
|
+
# --with-protoc=file:///path/to/protoc-*.zip \
|
|
22
22
|
# --with-sass-embedded=file:///path/to/sass_embedded-*.(tar.gz|zip) \
|
|
23
|
-
# --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
|
|
23
|
+
# --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
|
|
24
24
|
class Extconf
|
|
25
25
|
def initialize
|
|
26
26
|
get_with_config('protoc', true) { latest_protoc }
|
data/lib/sass.rb
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# The Sass module. This
|
|
3
|
+
# The Sass module. This communicates with Embedded Dart Sass using
|
|
4
4
|
# the Embedded Sass protocol.
|
|
5
5
|
module Sass
|
|
6
6
|
class << self
|
|
7
|
-
# The global include_paths for Sass files. This is meant for plugins and
|
|
7
|
+
# The global {.include_paths} for Sass files. This is meant for plugins and
|
|
8
8
|
# libraries to register the paths to their Sass stylesheets to that they may
|
|
9
|
-
# be `@
|
|
10
|
-
# {Sass::Embedded}. They are lower-precedence than any include
|
|
11
|
-
# in via the
|
|
9
|
+
# be included via `@import` or `@use`. This include path is used by every
|
|
10
|
+
# instance of {Sass::Embedded}. They are lower-precedence than any include
|
|
11
|
+
# paths passed in via the `include_paths` option.
|
|
12
12
|
#
|
|
13
13
|
# If the `SASS_PATH` environment variable is set,
|
|
14
14
|
# the initial value of `include_paths` will be initialized based on that.
|
|
@@ -17,7 +17,7 @@ module Sass
|
|
|
17
17
|
#
|
|
18
18
|
# @example
|
|
19
19
|
# Sass.include_paths << File.dirname(__FILE__) + '/sass'
|
|
20
|
-
# @return [Array
|
|
20
|
+
# @return [Array]
|
|
21
21
|
def include_paths
|
|
22
22
|
@include_paths ||= if ENV['SASS_PATH']
|
|
23
23
|
ENV['SASS_PATH'].split(File::PATH_SEPARATOR)
|
|
@@ -26,19 +26,26 @@ module Sass
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
# The global {.info} method. This instantiates a global {Embedded} instance
|
|
30
|
+
# and calls {Embedded#info}.
|
|
31
|
+
#
|
|
32
|
+
# @raise [ProtocolError]
|
|
29
33
|
def info
|
|
30
34
|
embedded.info
|
|
31
35
|
end
|
|
32
36
|
|
|
33
|
-
# The global render method. This
|
|
34
|
-
#
|
|
35
|
-
#
|
|
36
|
-
# for supported options.
|
|
37
|
+
# The global {.render} method. This instantiates a global {Embedded} instance
|
|
38
|
+
# and calls {Embedded#render}.
|
|
39
|
+
#
|
|
40
|
+
# See {file:README.md#options} for supported options.
|
|
41
|
+
#
|
|
37
42
|
# @example
|
|
38
43
|
# Sass.render(data: 'h1 { font-size: 40px; }')
|
|
39
44
|
# @example
|
|
40
45
|
# Sass.render(file: 'style.css')
|
|
41
|
-
# @return [
|
|
46
|
+
# @return [Result]
|
|
47
|
+
# @raise [ProtocolError]
|
|
48
|
+
# @raise [RenderError]
|
|
42
49
|
def render(**kwargs)
|
|
43
50
|
embedded.render(**kwargs)
|
|
44
51
|
end
|
|
@@ -53,12 +60,13 @@ module Sass
|
|
|
53
60
|
end
|
|
54
61
|
end
|
|
55
62
|
|
|
56
|
-
require_relative 'sass/version'
|
|
57
|
-
require_relative 'sass/error'
|
|
58
63
|
require_relative 'sass/platform'
|
|
59
64
|
require_relative 'sass/util'
|
|
65
|
+
require_relative 'sass/struct'
|
|
66
|
+
require_relative 'sass/result'
|
|
67
|
+
require_relative 'sass/error'
|
|
60
68
|
require_relative 'sass/transport'
|
|
61
69
|
require_relative 'sass/observer'
|
|
62
|
-
require_relative 'sass/
|
|
70
|
+
require_relative 'sass/version'
|
|
63
71
|
require_relative 'sass/render'
|
|
64
72
|
require_relative 'sass/embedded'
|
data/lib/sass/embedded.rb
CHANGED
|
@@ -4,8 +4,9 @@ require 'base64'
|
|
|
4
4
|
require 'json'
|
|
5
5
|
|
|
6
6
|
module Sass
|
|
7
|
-
# The {Embedded}
|
|
8
|
-
#
|
|
7
|
+
# The {Embedded} host for using dart-sass-embedded. Each instance creates
|
|
8
|
+
# its own {Transport}.
|
|
9
|
+
#
|
|
9
10
|
# @example
|
|
10
11
|
# embedded = Sass::Embedded.new
|
|
11
12
|
# result = embedded.render(data: 'h1 { font-size: 40px; }')
|
|
@@ -18,20 +19,28 @@ module Sass
|
|
|
18
19
|
@id = 0
|
|
19
20
|
end
|
|
20
21
|
|
|
22
|
+
# The {Embedded#info} method.
|
|
23
|
+
#
|
|
24
|
+
# @raise [ProtocolError]
|
|
21
25
|
def info
|
|
22
|
-
@info ||=
|
|
26
|
+
@info ||= Version.new(@transport, next_id).fetch
|
|
23
27
|
end
|
|
24
28
|
|
|
29
|
+
# The {Embedded#render} method.
|
|
30
|
+
#
|
|
31
|
+
# See {file:README.md#options} for supported options.
|
|
32
|
+
#
|
|
33
|
+
# @return [Result]
|
|
34
|
+
# @raise [ProtocolError]
|
|
35
|
+
# @raise [RenderError]
|
|
25
36
|
def render(data: nil,
|
|
26
37
|
file: nil,
|
|
27
38
|
indented_syntax: false,
|
|
28
39
|
include_paths: [],
|
|
29
40
|
output_style: :expanded,
|
|
30
|
-
# precision: 5,
|
|
31
41
|
indent_type: :space,
|
|
32
42
|
indent_width: 2,
|
|
33
43
|
linefeed: :lf,
|
|
34
|
-
# source_comments: false,
|
|
35
44
|
source_map: false,
|
|
36
45
|
out_file: nil,
|
|
37
46
|
omit_source_map_url: false,
|
|
@@ -46,41 +55,41 @@ module Sass
|
|
|
46
55
|
indent_width = parse_indent_width(indent_width)
|
|
47
56
|
linefeed = parse_linefeed(linefeed)
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if
|
|
58
|
+
message = Render.new(@transport, next_id,
|
|
59
|
+
data: data,
|
|
60
|
+
file: file,
|
|
61
|
+
indented_syntax: indented_syntax,
|
|
62
|
+
include_paths: include_paths,
|
|
63
|
+
output_style: output_style,
|
|
64
|
+
source_map: source_map,
|
|
65
|
+
out_file: out_file,
|
|
66
|
+
functions: functions,
|
|
67
|
+
importer: importer).fetch
|
|
68
|
+
|
|
69
|
+
if message.failure
|
|
61
70
|
raise RenderError.new(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if
|
|
71
|
+
message.failure.message,
|
|
72
|
+
message.failure.formatted,
|
|
73
|
+
if message.failure.span.nil?
|
|
65
74
|
nil
|
|
66
|
-
elsif
|
|
75
|
+
elsif message.failure.span.url == ''
|
|
67
76
|
'stdin'
|
|
68
77
|
else
|
|
69
|
-
Util.path(
|
|
78
|
+
Util.path(message.failure.span.url)
|
|
70
79
|
end,
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
message.failure.span ? message.failure.span.start.line + 1 : nil,
|
|
81
|
+
message.failure.span ? message.failure.span.start.column + 1 : nil,
|
|
73
82
|
1
|
|
74
83
|
)
|
|
75
84
|
end
|
|
76
85
|
|
|
77
|
-
map, source_map = post_process_map(map:
|
|
86
|
+
map, source_map = post_process_map(map: message.success.source_map,
|
|
78
87
|
file: file,
|
|
79
88
|
out_file: out_file,
|
|
80
89
|
source_map: source_map,
|
|
81
90
|
source_map_root: source_map_root)
|
|
82
91
|
|
|
83
|
-
css = post_process_css(css:
|
|
92
|
+
css = post_process_css(css: message.success.css,
|
|
84
93
|
indent_type: indent_type,
|
|
85
94
|
indent_width: indent_width,
|
|
86
95
|
linefeed: linefeed,
|
|
@@ -92,16 +101,9 @@ module Sass
|
|
|
92
101
|
|
|
93
102
|
finish = Util.now
|
|
94
103
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
stats: {
|
|
99
|
-
entry: file.nil? ? 'data' : file,
|
|
100
|
-
start: start,
|
|
101
|
-
end: finish,
|
|
102
|
-
duration: finish - start
|
|
103
|
-
}
|
|
104
|
-
}
|
|
104
|
+
stats = Result::Stats.new(file.nil? ? 'data' : file, start, finish, finish - start)
|
|
105
|
+
|
|
106
|
+
Result.new(css, map, stats)
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
def close
|
data/lib/sass/error.rb
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Sass
|
|
4
|
-
class
|
|
4
|
+
class Error < StandardError; end
|
|
5
5
|
|
|
6
|
-
class ProtocolError <
|
|
6
|
+
class ProtocolError < Error; end
|
|
7
7
|
|
|
8
|
-
# The
|
|
9
|
-
class RenderError <
|
|
10
|
-
|
|
8
|
+
# The {Error} raised by {Embedded#render}.
|
|
9
|
+
class RenderError < Error
|
|
10
|
+
include Struct
|
|
11
|
+
|
|
12
|
+
attr_reader :formatted, :file, :line, :column, :status
|
|
11
13
|
|
|
12
14
|
def initialize(message, formatted, file, line, column, status)
|
|
15
|
+
super(message)
|
|
13
16
|
@formatted = formatted
|
|
14
17
|
@file = file
|
|
15
18
|
@line = line
|
|
16
19
|
@column = column
|
|
17
20
|
@status = status
|
|
18
|
-
super(message)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
def backtrace
|
data/lib/sass/info.rb
CHANGED
data/lib/sass/observer.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Sass
|
|
4
|
-
# The
|
|
5
|
-
# from {Transport}.
|
|
4
|
+
# The {Observer} for receiving messages from {Transport}.
|
|
6
5
|
class Observer
|
|
7
6
|
def initialize(transport, id)
|
|
8
7
|
raise NotImplementedError if instance_of? Observer
|
data/lib/sass/result.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
# The {Result} of {Embedded#render}.
|
|
5
|
+
class Result
|
|
6
|
+
include Struct
|
|
7
|
+
|
|
8
|
+
attr_reader :css, :map, :stats
|
|
9
|
+
|
|
10
|
+
def initialize(css, map, stats)
|
|
11
|
+
@css = css
|
|
12
|
+
@map = map
|
|
13
|
+
@stats = stats
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# The {Stats} of {Embedded#render}.
|
|
17
|
+
class Stats
|
|
18
|
+
include Struct
|
|
19
|
+
|
|
20
|
+
attr_reader :entry, :start, :end, :duration
|
|
21
|
+
|
|
22
|
+
def initialize(entry, start, finish, duration)
|
|
23
|
+
@entry = entry
|
|
24
|
+
@start = start
|
|
25
|
+
@end = finish
|
|
26
|
+
@duration = duration
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/lib/sass/struct.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
# The {Struct} module.
|
|
5
|
+
module Struct
|
|
6
|
+
def [](key)
|
|
7
|
+
instance_variable_get("@#{key}".to_sym)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def to_h
|
|
11
|
+
instance_variables.map do |variable|
|
|
12
|
+
[variable[1..].to_sym, instance_variable_get(variable)]
|
|
13
|
+
end.to_h
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
to_h.to_s
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/sass/transport.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative '../../ext/embedded_sass_pb'
|
|
|
6
6
|
|
|
7
7
|
module Sass
|
|
8
8
|
# The {Observable} {Transport} for low level communication with
|
|
9
|
-
# dart-sass-embedded using protocol buffers via stdio. Received messages
|
|
9
|
+
# `dart-sass-embedded` using protocol buffers via stdio. Received messages
|
|
10
10
|
# can be observed by an {Observer}.
|
|
11
11
|
class Transport
|
|
12
12
|
include Observable
|
data/lib/sass/util.rb
CHANGED
data/lib/sass/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sass-embedded
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- なつき
|
|
@@ -161,6 +161,8 @@ files:
|
|
|
161
161
|
- lib/sass/observer.rb
|
|
162
162
|
- lib/sass/platform.rb
|
|
163
163
|
- lib/sass/render.rb
|
|
164
|
+
- lib/sass/result.rb
|
|
165
|
+
- lib/sass/struct.rb
|
|
164
166
|
- lib/sass/transport.rb
|
|
165
167
|
- lib/sass/util.rb
|
|
166
168
|
- lib/sass/version.rb
|