glimmer-dsl-css 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +101 -4
- data/VERSION +1 -1
- data/bin/css_to_glimmer +19 -0
- data/bin/minify_css +20 -0
- data/glimmer-dsl-css.gemspec +9 -2
- data/lib/glimmer/css/css_minifier.rb +30 -0
- data/lib/glimmer/css/css_to_glimmer_converter.rb +121 -0
- data/lib/glimmer/css/media_query.rb +3 -0
- data/lib/glimmer/dsl/css/display_expression.rb +33 -0
- data/lib/glimmer/dsl/css/dsl.rb +1 -0
- metadata +29 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63ac41960245ceacb5eaec363a41bf8f80e56bdea6e150f68a16266b88b96937
|
4
|
+
data.tar.gz: 40ead61962a906cd7ecf1703afcb5b0998b369416e026e17a0b2cebe3aa770f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07ef93287f2769c303d1159d451468d33d5c6cff4aa81679fa5ff559bc733fbc834d26daf909a7db5f03928b9ced56efef39f34b83d2ffd65a7b5fbb219918ce
|
7
|
+
data.tar.gz: e9fee33a86f2ba56bc8e9f43071a437e440a0b68f1e9f3bd0755f4497138188118e7d7812860c2f7590f59b23008e2b473dec3ac49746fcb27b10d8becaac51b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.4.0
|
4
|
+
|
5
|
+
- `css_to_glimmer` converter command for automatically converting CSS to Glimmer DSL Ruby code
|
6
|
+
- `css_to_glimmer` -r=rule_keyword option to customize rule keyword (rule has aliases: rul, ru, r, s, _)
|
7
|
+
- `minifier` converter command for automatically minifying CSS
|
8
|
+
- Fix issue with `display` CSS property not getting interpreted successfully in Glimmer DSL Ruby code
|
9
|
+
|
3
10
|
## 1.3.0
|
4
11
|
|
5
12
|
- Support media queries
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for CSS 1.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for CSS 1.4.0
|
2
2
|
## Ruby Programmable Cascading Style Sheets
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-css.svg)](http://badge.fury.io/rb/glimmer-dsl-css)
|
4
4
|
[![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-css.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-css)
|
@@ -6,13 +6,15 @@
|
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/c7365cdb8556be433115/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-css/maintainability)
|
7
7
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
8
|
|
9
|
-
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for CSS provides Ruby syntax for building CSS (Cascading Style Sheets). It used to be part of the [Glimmer](https://github.com/AndyObtiva/glimmer) library (created in 2007), but eventually got extracted into its own project.
|
9
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for CSS provides Ruby syntax for building CSS (Cascading Style Sheets). It used to be part of the [Glimmer](https://github.com/AndyObtiva/glimmer) library (created in 2007), but eventually got extracted into its own project. The Ruby gem also includes a [CSS to Glimmer converter](#css-to-glimmer-converter) (`css_to_glimmer`) to automatically convert legacy CSS code into Glimmer DSL syntax.
|
10
10
|
|
11
11
|
Example (you can try in IRB):
|
12
12
|
|
13
13
|
```ruby
|
14
14
|
require 'glimmer-dsl-css'
|
15
|
+
|
15
16
|
include Glimmer
|
17
|
+
|
16
18
|
@css = css {
|
17
19
|
body {
|
18
20
|
font_size '1.1em'
|
@@ -31,6 +33,7 @@ include Glimmer
|
|
31
33
|
}
|
32
34
|
}
|
33
35
|
}
|
36
|
+
|
34
37
|
puts @css
|
35
38
|
```
|
36
39
|
|
@@ -61,7 +64,7 @@ Please follow these instructions to make the `glimmer` command available on your
|
|
61
64
|
|
62
65
|
Run this command to install directly:
|
63
66
|
```
|
64
|
-
gem install glimmer-dsl-css -v 1.
|
67
|
+
gem install glimmer-dsl-css -v 1.4.0
|
65
68
|
```
|
66
69
|
|
67
70
|
Note: In case you are using JRuby, `jgem` is JRuby's version of the `gem` command. RVM allows running `gem` as an alias in JRuby. Otherwise, you may also run `jruby -S gem install ...`
|
@@ -76,7 +79,7 @@ That's it! Requiring the gem activates the Glimmer CSS DSL automatically.
|
|
76
79
|
|
77
80
|
Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
|
78
81
|
```
|
79
|
-
gem 'glimmer-dsl-css', '~> 1.
|
82
|
+
gem 'glimmer-dsl-css', '~> 1.4.0'
|
80
83
|
```
|
81
84
|
|
82
85
|
And, then run:
|
@@ -115,17 +118,21 @@ Example (you can try in IRB):
|
|
115
118
|
|
116
119
|
```ruby
|
117
120
|
require 'glimmer-dsl-css'
|
121
|
+
|
118
122
|
include Glimmer
|
123
|
+
|
119
124
|
@css = css {
|
120
125
|
body {
|
121
126
|
font_size '1.1em'
|
122
127
|
background 'white'
|
123
128
|
}
|
129
|
+
|
124
130
|
r('body > h1') {
|
125
131
|
background_color :red
|
126
132
|
font_size 24
|
127
133
|
}
|
128
134
|
}
|
135
|
+
|
129
136
|
puts @css
|
130
137
|
```
|
131
138
|
|
@@ -171,7 +178,9 @@ As you saw above, numeric values (e.g. `24` in `font_size 24`) automatically get
|
|
171
178
|
|
172
179
|
```ruby
|
173
180
|
require 'glimmer-dsl-css'
|
181
|
+
|
174
182
|
include Glimmer
|
183
|
+
|
175
184
|
@css = css {
|
176
185
|
body {
|
177
186
|
font_size '1.1em'
|
@@ -182,6 +191,7 @@ include Glimmer
|
|
182
191
|
font_size 24
|
183
192
|
end
|
184
193
|
}
|
194
|
+
|
185
195
|
puts @css
|
186
196
|
```
|
187
197
|
|
@@ -191,6 +201,93 @@ Output (minified CSS):
|
|
191
201
|
body{font-size:1.1em;background:white}body > h1{background-color:red;font-size:24px}
|
192
202
|
```
|
193
203
|
|
204
|
+
### CSS to Glimmer Converter
|
205
|
+
|
206
|
+
The Ruby gem includes a CSS to Glimmer converter (`css_to_glimmer`) to automatically convert legacy CSS code into Glimmer DSL syntax.
|
207
|
+
|
208
|
+
Script:
|
209
|
+
|
210
|
+
[bin/css_to_glimmer](/bin/css_to_glimmer)
|
211
|
+
|
212
|
+
Usage:
|
213
|
+
|
214
|
+
```
|
215
|
+
css_to_glimmer [-r=rule_keyword] path_to_css_file
|
216
|
+
```
|
217
|
+
|
218
|
+
Example:
|
219
|
+
|
220
|
+
```
|
221
|
+
css_to_glimmer input.css
|
222
|
+
```
|
223
|
+
|
224
|
+
Prints:
|
225
|
+
|
226
|
+
```
|
227
|
+
Converting from CSS syntax to Glimmer DSL Ruby syntax for input file: input.css
|
228
|
+
Converted output file: input.css.glimmer.rb
|
229
|
+
```
|
230
|
+
|
231
|
+
Output file (`input.css.glimmer.rb`) is a runnable Ruby file containing Glimmer DSL for CSS syntax:
|
232
|
+
|
233
|
+
```
|
234
|
+
require 'glimmer-dsl-css'
|
235
|
+
|
236
|
+
include Glimmer
|
237
|
+
|
238
|
+
style_sheet = css {
|
239
|
+
rule('html,body') {
|
240
|
+
margin '0'
|
241
|
+
padding '0'
|
242
|
+
}
|
243
|
+
|
244
|
+
media('(max-width: 430px)') {
|
245
|
+
rule('.footer') {
|
246
|
+
height '50px'
|
247
|
+
}
|
248
|
+
|
249
|
+
rule('.filters') {
|
250
|
+
bottom '10px'
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
puts style_sheet.to_s
|
256
|
+
```
|
257
|
+
|
258
|
+
If you would rather customize the `rule` keyword with a shorter alias like `rul`, `ru`, `r`, `s` (for selector), or `_`, you can run the following command:
|
259
|
+
|
260
|
+
```
|
261
|
+
css_to_glimmer -r=ru input.css
|
262
|
+
```
|
263
|
+
|
264
|
+
Output file (`input.css.glimmer.rb`) is a runnable Ruby file containing Glimmer DSL for CSS syntax:
|
265
|
+
|
266
|
+
```
|
267
|
+
require 'glimmer-dsl-css'
|
268
|
+
|
269
|
+
include Glimmer
|
270
|
+
|
271
|
+
style_sheet = css {
|
272
|
+
ru('html,body') {
|
273
|
+
margin '0'
|
274
|
+
padding '0'
|
275
|
+
}
|
276
|
+
|
277
|
+
media('(max-width: 430px)') {
|
278
|
+
ru('.footer') {
|
279
|
+
height '50px'
|
280
|
+
}
|
281
|
+
|
282
|
+
ru('.filters') {
|
283
|
+
bottom '10px'
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
puts style_sheet.to_s
|
289
|
+
```
|
290
|
+
|
194
291
|
## Multi-DSL Support
|
195
292
|
|
196
293
|
Learn more about how to use this DSL alongside other Glimmer DSLs:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/bin/css_to_glimmer
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/glimmer/css/css_to_glimmer_converter'
|
4
|
+
|
5
|
+
usage = "***Glimmer DSL for CSS - CSS to Glimmer Converter***\nUsage: css_to_glimmer path_to_css_file"
|
6
|
+
|
7
|
+
if ARGV.empty?
|
8
|
+
puts usage
|
9
|
+
else
|
10
|
+
css_file_path = ARGV.last
|
11
|
+
puts "Converting from CSS syntax to Glimmer DSL Ruby syntax for input file: #{css_file_path}"
|
12
|
+
css = File.read(css_file_path)
|
13
|
+
rule_keyword = ARGV.find { |arg| arg.start_with?("-r=") }.to_s.split('=')[1].to_s
|
14
|
+
converter = rule_keyword.empty? ? Glimmer::CSS::CSSToGlimmerConverter.new : Glimmer::CSS::CSSToGlimmerConverter.new(rule_keyword: rule_keyword)
|
15
|
+
glimmer = converter.convert(css)
|
16
|
+
glimmer_file_path = "#{css_file_path}.glimmer.rb"
|
17
|
+
File.write(glimmer_file_path, glimmer)
|
18
|
+
puts "Converted output file: #{glimmer_file_path}"
|
19
|
+
end
|
data/bin/minify_css
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/glimmer/css/css_minifier'
|
4
|
+
|
5
|
+
usage = "***Glimmer DSL for CSS - CSS Minifier***\nUsage: minify_css path_to_css_file"
|
6
|
+
|
7
|
+
# TODO support option to select rule, or rul, or r
|
8
|
+
|
9
|
+
if ARGV.empty?
|
10
|
+
puts usage
|
11
|
+
else
|
12
|
+
css_file_path = ARGV.first
|
13
|
+
puts "Minifying CSS for input file: #{css_file_path}"
|
14
|
+
css = File.read(css_file_path)
|
15
|
+
converter = Glimmer::CSS::CSSMinifier.new
|
16
|
+
minified_css = converter.convert(css)
|
17
|
+
minified_css_file_path = "#{File.basename(css_file_path, '.css')}.minified.css"
|
18
|
+
File.write(minified_css_file_path, minified_css)
|
19
|
+
puts "Converted output file: #{minified_css_file_path}"
|
20
|
+
end
|
data/glimmer-dsl-css.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: glimmer-dsl-css 1.
|
5
|
+
# stub: glimmer-dsl-css 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "glimmer-dsl-css".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.date = "2024-05-18"
|
15
15
|
s.description = "Glimmer DSL for CSS (Ruby Programmable Cascading Style Sheets)".freeze
|
16
16
|
s.email = "andy.am@gmail.com".freeze
|
17
|
+
s.executables = ["css_to_glimmer".freeze, "minify_css".freeze]
|
17
18
|
s.extra_rdoc_files = [
|
18
19
|
"CHANGELOG.md",
|
19
20
|
"LICENSE.txt",
|
@@ -25,13 +26,18 @@ Gem::Specification.new do |s|
|
|
25
26
|
"LICENSE.txt",
|
26
27
|
"README.md",
|
27
28
|
"VERSION",
|
29
|
+
"bin/css_to_glimmer",
|
30
|
+
"bin/minify_css",
|
28
31
|
"glimmer-dsl-css.gemspec",
|
29
32
|
"lib/glimmer-dsl-css.rb",
|
33
|
+
"lib/glimmer/css/css_minifier.rb",
|
34
|
+
"lib/glimmer/css/css_to_glimmer_converter.rb",
|
30
35
|
"lib/glimmer/css/media_query.rb",
|
31
36
|
"lib/glimmer/css/rule.rb",
|
32
37
|
"lib/glimmer/css/rule_composite.rb",
|
33
38
|
"lib/glimmer/css/style_sheet.rb",
|
34
39
|
"lib/glimmer/dsl/css/css_expression.rb",
|
40
|
+
"lib/glimmer/dsl/css/display_expression.rb",
|
35
41
|
"lib/glimmer/dsl/css/dsl.rb",
|
36
42
|
"lib/glimmer/dsl/css/dynamic_property_expression.rb",
|
37
43
|
"lib/glimmer/dsl/css/element_rule_expression.rb",
|
@@ -52,6 +58,7 @@ Gem::Specification.new do |s|
|
|
52
58
|
s.specification_version = 4
|
53
59
|
|
54
60
|
s.add_runtime_dependency(%q<glimmer>.freeze, [">= 2.0.0", "< 3.0.0"])
|
61
|
+
s.add_runtime_dependency(%q<css_parser>.freeze, [">= 1.0.0", "< 2.0.0"])
|
55
62
|
s.add_development_dependency(%q<rspec-mocks>.freeze, ["~> 3.0"])
|
56
63
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.0"])
|
57
64
|
s.add_development_dependency(%q<puts_debuggerer>.freeze, [">= 0"])
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright (c) 2020-2024 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
module Glimmer
|
23
|
+
module CSS
|
24
|
+
class CSSMinifier
|
25
|
+
def convert(css)
|
26
|
+
css.lines.map(&:chomp).map(&:strip).join
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# Copyright (c) 2020-2024 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'css_parser'
|
23
|
+
require_relative 'css_minifier'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module CSS
|
27
|
+
class CSSToGlimmerConverter
|
28
|
+
include CssParser
|
29
|
+
|
30
|
+
RULE_KEYWORDS = %w[rule rul ru r s _]
|
31
|
+
|
32
|
+
# This option specifies if we want to use the default rule keyword or an alias like rul or r
|
33
|
+
attr_reader :rule_keyword
|
34
|
+
|
35
|
+
def initialize(rule_keyword: 'rule')
|
36
|
+
@rule_keyword = rule_keyword.to_s
|
37
|
+
validate_rule_keyword
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert(css)
|
41
|
+
glimmer = ''
|
42
|
+
glimmer += "require 'glimmer-dsl-css'\n\n"
|
43
|
+
glimmer += "include Glimmer\n\n"
|
44
|
+
glimmer += "style_sheet = css {\n"
|
45
|
+
glimmer += convert_css(css).lines.map { |line| " #{line}" }.join
|
46
|
+
glimmer += "}\n\n"
|
47
|
+
glimmer += "puts style_sheet.to_s\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
def minify(css)
|
51
|
+
CSSMinifier.new.convert(css)
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_charset(css)
|
55
|
+
css.sub(/@charset[^;]*;/, '')
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_comments(css)
|
59
|
+
output = ''
|
60
|
+
comment = false
|
61
|
+
current_two_characters = [];
|
62
|
+
css.chars.each do |character|
|
63
|
+
output << character if !comment
|
64
|
+
current_two_characters.shift if current_two_characters.size == 2
|
65
|
+
current_two_characters << character
|
66
|
+
if !comment && current_two_characters.join == '/*'
|
67
|
+
comment = true
|
68
|
+
output = output[0...-2]
|
69
|
+
elsif comment && current_two_characters.join == '*/'
|
70
|
+
comment = false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
output
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
def convert_css(css)
|
79
|
+
parser = CssParser::Parser.new
|
80
|
+
parser.load_string!(css)
|
81
|
+
parser.rules_by_media_query.map do |media_query, rule_set|
|
82
|
+
if media_query == :all
|
83
|
+
convert_rule_set_to_glimmer(rule_set)
|
84
|
+
else
|
85
|
+
convert_media_query_rule_set_to_glimmer(rule_set, media_query)
|
86
|
+
end
|
87
|
+
end.join("\n")
|
88
|
+
end
|
89
|
+
|
90
|
+
def convert_rule_set_to_glimmer(rule_set)
|
91
|
+
glimmer = ''
|
92
|
+
rule_set.each_with_index do |rule, index|
|
93
|
+
glimmer += "\n" if index > 0
|
94
|
+
rule_selector = rule.selectors.join(', ').gsub("'", '"')
|
95
|
+
glimmer += "#{rule_keyword}('#{rule_selector}') {\n"
|
96
|
+
rule.each_declaration do |declaration, value|
|
97
|
+
property_name = declaration.gsub('-', '_')
|
98
|
+
property_value = value.sub(/^("|')/, '').sub(/("|')$/, '').gsub("'", '"')
|
99
|
+
glimmer += " #{property_name} '#{property_value}'\n"
|
100
|
+
end
|
101
|
+
glimmer += "}\n"
|
102
|
+
end
|
103
|
+
glimmer
|
104
|
+
end
|
105
|
+
|
106
|
+
def convert_media_query_rule_set_to_glimmer(rule_set, media_query)
|
107
|
+
glimmer = ''
|
108
|
+
glimmer += "media('#{media_query.to_s.gsub("'", '"')}') {\n"
|
109
|
+
glimmer += convert_rule_set_to_glimmer(rule_set).lines.map { |line| " #{line}" }.join
|
110
|
+
glimmer += "}\n"
|
111
|
+
glimmer
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def validate_rule_keyword
|
117
|
+
raise "rule_keyword '#{rule_keyword}' is invalid! It must be 'rule', 'rul', 'ru', 'r', 's', or '_'" if !RULE_KEYWORDS.include?(rule_keyword)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -19,6 +19,9 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require 'glimmer/css/rule_composite'
|
23
|
+
require 'glimmer/css/rule'
|
24
|
+
|
22
25
|
module Glimmer
|
23
26
|
module CSS
|
24
27
|
class MediaQuery < Rule
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Copyright (c) 2020-2024 - Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/dsl/static_expression'
|
23
|
+
require 'glimmer/dsl/css/property_expression'
|
24
|
+
|
25
|
+
module Glimmer
|
26
|
+
module DSL
|
27
|
+
module CSS
|
28
|
+
class DisplayExpression < StaticExpression
|
29
|
+
include PropertyExpression
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/glimmer/dsl/css/dsl.rb
CHANGED
@@ -29,6 +29,7 @@ require 'glimmer/dsl/css/rul_expression'
|
|
29
29
|
require 'glimmer/dsl/css/ru_expression'
|
30
30
|
require 'glimmer/dsl/css/s_expression'
|
31
31
|
require 'glimmer/dsl/css/pv_expression'
|
32
|
+
require 'glimmer/dsl/css/display_expression'
|
32
33
|
require 'glimmer/dsl/css/media_expression'
|
33
34
|
|
34
35
|
module Glimmer
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AndyMaleh
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: css_parser
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.0.0
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.0.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.0.0
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.0.0
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: rspec-mocks
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,7 +210,9 @@ dependencies:
|
|
190
210
|
version: '0'
|
191
211
|
description: Glimmer DSL for CSS (Ruby Programmable Cascading Style Sheets)
|
192
212
|
email: andy.am@gmail.com
|
193
|
-
executables:
|
213
|
+
executables:
|
214
|
+
- css_to_glimmer
|
215
|
+
- minify_css
|
194
216
|
extensions: []
|
195
217
|
extra_rdoc_files:
|
196
218
|
- CHANGELOG.md
|
@@ -202,13 +224,18 @@ files:
|
|
202
224
|
- LICENSE.txt
|
203
225
|
- README.md
|
204
226
|
- VERSION
|
227
|
+
- bin/css_to_glimmer
|
228
|
+
- bin/minify_css
|
205
229
|
- glimmer-dsl-css.gemspec
|
206
230
|
- lib/glimmer-dsl-css.rb
|
231
|
+
- lib/glimmer/css/css_minifier.rb
|
232
|
+
- lib/glimmer/css/css_to_glimmer_converter.rb
|
207
233
|
- lib/glimmer/css/media_query.rb
|
208
234
|
- lib/glimmer/css/rule.rb
|
209
235
|
- lib/glimmer/css/rule_composite.rb
|
210
236
|
- lib/glimmer/css/style_sheet.rb
|
211
237
|
- lib/glimmer/dsl/css/css_expression.rb
|
238
|
+
- lib/glimmer/dsl/css/display_expression.rb
|
212
239
|
- lib/glimmer/dsl/css/dsl.rb
|
213
240
|
- lib/glimmer/dsl/css/dynamic_property_expression.rb
|
214
241
|
- lib/glimmer/dsl/css/element_rule_expression.rb
|