sass-embedded 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 105fb9a8f27198dc74d89911ec31eafc40e7cf786a9567d993f584c956169014
4
- data.tar.gz: e381b1d5c74d5356dfa9c6085bc7f6ed088259c90a80051dc22cbdf975fc1642
3
+ metadata.gz: 29224ce0b935055ad1b8a1bea0f0177d0c80ec51edcbf9fc6ad31036cbf93e30
4
+ data.tar.gz: 88ccf669d8cc196923c5dbbf3c488be00b22b39a6b59e18bad5bd3b3b6292981
5
5
  SHA512:
6
- metadata.gz: a33ebf10f59766f644e2c88be19ea2aa72bb78a45684f65092be5c386d977437f928fa5d63a9dde96d31f777e72a6a30b36be8959a22dbc4da02c090278ff01d
7
- data.tar.gz: '096e8913f2d9d4f402625d2f479e68ca772fffeaa8135ef078538af43052765753339fe9c1e3f378464f8d26d5dcffb113f2783754cd17bb24e097343a12b8fb'
6
+ metadata.gz: 8bfc272b296c6182dd638bc68864b8e1cdfee4f3fc3f5983ec3a870fe2506c30af87ef5477f2f62ef384ec2a22686971ed3941a74134335ecb5e47a951b45a4c
7
+ data.tar.gz: 49d1c4cae407da60e0831eefcce86522e5cb3403aef1d20bbc7d4cb093c814472a9143b043fee3293a18042e6464aa5195d279eef0eac21e2ce7bb5783652636
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Embedded Sass Host for Ruby
2
2
 
3
- [![build](https://github.com/ntkme/embedded-host-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ntkme/embedded-host-ruby/actions/workflows/build.yml)
3
+ [![build](https://github.com/ntkme/sass-embedded-host-ruby/actions/workflows/build.yml/badge.svg)](https://github.com/ntkme/sass-embedded-host-ruby/actions/workflows/build.yml)
4
4
  [![gem](https://badge.fury.io/rb/sass-embedded.svg)](https://rubygems.org/gems/sass-embedded)
5
5
 
6
6
  This is a Ruby library that implements the host side of the [Embedded Sass protocol](https://github.com/sass/sass-embedded-protocol).
@@ -20,7 +20,7 @@ The Ruby API provides two entrypoints for compiling Sass to CSS.
20
20
  - `Sass.compile` takes a path to a Sass file and return the result of compiling that file to CSS.
21
21
 
22
22
  ``` ruby
23
- require 'sass'
23
+ require 'sass-embedded'
24
24
 
25
25
  result = Sass.compile('style.scss')
26
26
  puts result.css
@@ -29,7 +29,7 @@ puts result.css
29
29
  - `Sass.compile_string` takes a string that represents the contents of a Sass file and return the result of compiling that file to CSS.
30
30
 
31
31
  ``` ruby
32
- require 'sass'
32
+ require 'sass-embedded'
33
33
 
34
34
  result = Sass.compile_string('h1 { font-size: 40px; }')
35
35
  puts result.css
data/ext/sass/Rakefile CHANGED
@@ -63,45 +63,54 @@ module FileUtils
63
63
  sh 'unzip', '-od', dest, archive
64
64
  end
65
65
  else
66
- raise "Unknown archive format #{archive}"
66
+ raise ArgumentError, "Unknown archive format #{archive}"
67
67
  end
68
68
  end
69
69
 
70
- def fetch(uri_or_path, dest = nil)
71
- require 'open-uri'
70
+ def fetch(source_uri, dest_path = nil)
71
+ require 'rubygems/remote_fetcher'
72
72
 
73
- begin
74
- uri = URI.parse(uri_or_path)
75
- path = URI::DEFAULT_PARSER.unescape(uri.path)
76
- if uri.instance_of?(URI::File) || uri.instance_of?(URI::Generic)
77
- path = path.delete_prefix('/') if Gem.win_platform? && !File.file?(path)
78
- raise unless File.file?(path)
73
+ unless source_uri.is_a?(URI::Generic)
74
+ begin
75
+ source_uri = URI.parse(source_uri)
76
+ rescue StandardError
77
+ source_uri = URI.parse(URI::DEFAULT_PARSER.escape(source_uri.to_s))
79
78
  end
80
- rescue StandardError
81
- raise unless File.file?(uri_or_path)
79
+ end
80
+
81
+ scheme = source_uri.scheme
82
+ source_path = URI::DEFAULT_PARSER.unescape(source_uri.path || source_uri.opaque)
82
83
 
83
- uri = nil
84
- path = uri_or_path
84
+ if Gem.win_platform? && scheme =~ /^[a-z]$/i && !source_path.include?(':')
85
+ source_path = "#{scheme}:#{source_path}"
86
+ scheme = nil
85
87
  end
86
88
 
87
- dest = File.basename(path) if dest.nil?
89
+ dest_path = File.basename(source_path) if dest_path.nil?
88
90
 
89
- if uri.nil? || uri.instance_of?(URI::File) || uri.instance_of?(URI::Generic)
90
- cp path, dest
91
- elsif uri.respond_to?(:open)
92
- Rake.rake_output_message "curl -fsSLo #{dest} -- #{uri}" if Rake::FileUtilsExt.verbose_flag
93
- unless Rake::FileUtilsExt.nowrite_flag
94
- uri.open do |stream|
95
- File.binwrite(dest, stream.read)
96
- end
91
+ case scheme
92
+ when nil, 'file'
93
+ if Gem.win_platform? && source_path[0].chr == '/' && source_path[1].chr =~ /[a-z]/i && source_path[2].chr == ':'
94
+ source_path = source_path[1..]
97
95
  end
96
+ cp source_path, dest_path
98
97
  else
99
- raise
98
+ fetcher = Gem::RemoteFetcher.fetcher
99
+ symbol = "fetch_#{scheme}".to_sym
100
+ raise ArgumentError, "Unsupported URI scheme #{scheme}" unless fetcher.respond_to?(symbol)
101
+
102
+ if Rake::FileUtilsExt.verbose_flag
103
+ redacted_uri = Gem::RemoteFetcher::FetchError.new('', source_uri).uri
104
+ Rake.rake_output_message "fetch #{redacted_uri}"
105
+ end
106
+
107
+ unless Rake::FileUtilsExt.nowrite_flag
108
+ data = fetcher.public_send(symbol, source_uri)
109
+ Gem.write_binary(dest_path, data)
110
+ end
100
111
  end
101
112
 
102
- dest
103
- rescue StandardError
104
- raise IOError, "Failed to fetch #{uri_or_path}"
113
+ dest_path
105
114
  end
106
115
  end
107
116
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '1.1.0'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -16,7 +16,58 @@ require_relative 'embedded/version'
16
16
  require_relative 'logger'
17
17
  require_relative 'value'
18
18
 
19
+ # The Sass module.
20
+ #
21
+ # This communicates with Embedded Dart Sass using the Embedded Sass protocol.
22
+ #
23
+ # @example
24
+ # Sass.compile('style.scss')
25
+ #
26
+ # @example
27
+ # Sass.compile_string('h1 { font-size: 40px; }')
19
28
  module Sass
29
+ class << self
30
+ # Compiles the Sass file at +path+ to CSS.
31
+ # @param (see Embedded#compile)
32
+ # @return (see Embedded#compile)
33
+ # @raise (see Embedded#compile)
34
+ # @see Embedded#compile
35
+ def compile(path, **kwargs)
36
+ instance.compile(path, **kwargs)
37
+ end
38
+
39
+ # Compiles a stylesheet whose contents is +source+ to CSS.
40
+ # @param (see Embedded#compile_string)
41
+ # @return (see Embedded#compile_string)
42
+ # @raise (see Embedded#compile_string)
43
+ # @see Embedded#compile_string
44
+ def compile_string(source, **kwargs)
45
+ instance.compile_string(source, **kwargs)
46
+ end
47
+
48
+ # @param (see Embedded#info)
49
+ # @return (see Embedded#info)
50
+ # @raise (see Embedded#info)
51
+ # @see Embedded#info
52
+ def info
53
+ instance.info
54
+ end
55
+
56
+ private
57
+
58
+ def instance
59
+ if defined? @instance
60
+ @instance = Embedded.new if @instance.closed?
61
+ else
62
+ @instance = Embedded.new
63
+ at_exit do
64
+ @instance.close
65
+ end
66
+ end
67
+ @instance
68
+ end
69
+ end
70
+
20
71
  # The {Embedded} host for using dart-sass-embedded. Each instance creates
21
72
  # its own communication {Channel} with a dedicated compiler process.
22
73
  #
data/lib/sass-embedded.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative 'sass'
4
+ require_relative 'sass/embedded'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -123,7 +123,6 @@ files:
123
123
  - ext/sass/package.json
124
124
  - ext/sass/unzip.vbs
125
125
  - lib/sass-embedded.rb
126
- - lib/sass.rb
127
126
  - lib/sass/compile_error.rb
128
127
  - lib/sass/compile_result.rb
129
128
  - lib/sass/embedded.rb
@@ -160,8 +159,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
160
159
  licenses:
161
160
  - MIT
162
161
  metadata:
163
- documentation_uri: https://rubydoc.info/gems/sass-embedded/1.1.0
164
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.1.0
162
+ documentation_uri: https://rubydoc.info/gems/sass-embedded/1.2.0
163
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.2.0
165
164
  funding_uri: https://github.com/sponsors/ntkme
166
165
  post_install_message:
167
166
  rdoc_options: []
data/lib/sass.rb DELETED
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'sass/embedded'
4
-
5
- # The Sass module.
6
- #
7
- # This communicates with Embedded Dart Sass using the Embedded Sass protocol.
8
- #
9
- # @example
10
- # Sass.compile('style.scss')
11
- #
12
- # @example
13
- # Sass.compile_string('h1 { font-size: 40px; }')
14
- module Sass
15
- class << self
16
- # Compiles the Sass file at +path+ to CSS.
17
- # @param (see Embedded#compile)
18
- # @return (see Embedded#compile)
19
- # @raise (see Embedded#compile)
20
- # @see Embedded#compile
21
- def compile(path, **kwargs)
22
- instance.compile(path, **kwargs)
23
- end
24
-
25
- # Compiles a stylesheet whose contents is +source+ to CSS.
26
- # @param (see Embedded#compile_string)
27
- # @return (see Embedded#compile_string)
28
- # @raise (see Embedded#compile_string)
29
- # @see Embedded#compile_string
30
- def compile_string(source, **kwargs)
31
- instance.compile_string(source, **kwargs)
32
- end
33
-
34
- # @param (see Embedded#info)
35
- # @return (see Embedded#info)
36
- # @raise (see Embedded#info)
37
- # @see Embedded#info
38
- def info
39
- instance.info
40
- end
41
-
42
- private
43
-
44
- def instance
45
- if defined? @instance
46
- @instance = Embedded.new if @instance.closed?
47
- else
48
- @instance = Embedded.new
49
- at_exit do
50
- @instance.close
51
- end
52
- end
53
- @instance
54
- end
55
- end
56
- end