glimmer-dsl-css 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96e2646830dfe42a2cfe0ea91ea369b558d0873917071e963349856b129c1278
4
- data.tar.gz: 1948d00677cdf1aa4df5cbb90a4632edbd06c03c6162dce55ca2ebb94baa0dff
3
+ metadata.gz: 4d7025737d0f0a5d69fa10f2410f119e35037300e0b588ac71cbcc93d2bcc37e
4
+ data.tar.gz: 6123b4db4d7f8e575e0d3480f9709a5c4b69da3a1a5404b163577a6acb0df299
5
5
  SHA512:
6
- metadata.gz: 4dac6e584522cc6d193aac0ff4cf6fac528e4fa940bf1d95de6c35e657333852627248fc783e20d9844313a43a82b05915dbd1b457304bfc15124575cf8323ed
7
- data.tar.gz: 595521b5d0d22be9ff481db6bc0a7a18ad0bc4d5958d9e69a77886b03961b6ea9d1a79d74f4e783ce418cdceb2cf53fb0190656d84eabe95e5f8039908cadb59
6
+ metadata.gz: 1860dbc22baf525cc80be2df7ae16f9a6b1f158e42f00ead107c1440ca4d75579392f51c19371372fcb063416db62b0831e675cb54856dba2ee9a07218d5a5b0
7
+ data.tar.gz: 13db5825e60924567f8004d1c20a6fe5e822b1a2a739fc6791e831cc72a9c77083009312212b19393901783128928ebaadb39f39b7fcfd5aafb1e78f4a274e66
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.5.0
4
+
5
+ - Support `raw` keyword to allow adding raw CSS to a `css { }` block, which gets appended to other CSS generated by the DSL.
6
+
3
7
  ## 1.4.1
4
8
 
5
9
  - Optimize performance (mostly in Opal) by re-ordering dsl.rb to give preference to dynamic property expressions, removing media from its chain of responsibility (it does not need to be there because it is a static expression), and re-ordering conditional checks in dynamic property expression and element rule expression.
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.4.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.5.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)
@@ -64,7 +64,7 @@ Please follow these instructions to make the `glimmer` command available on your
64
64
 
65
65
  Run this command to install directly:
66
66
  ```
67
- gem install glimmer-dsl-css -v 1.4.1
67
+ gem install glimmer-dsl-css -v 1.5.0
68
68
  ```
69
69
 
70
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 ...`
@@ -79,7 +79,7 @@ That's it! Requiring the gem activates the Glimmer CSS DSL automatically.
79
79
 
80
80
  Add the following to `Gemfile` (after `glimmer-dsl-swt` and/or `glimmer-dsl-opal` if included too):
81
81
  ```
82
- gem 'glimmer-dsl-css', '~> 1.4.1'
82
+ gem 'glimmer-dsl-css', '~> 1.5.0'
83
83
  ```
84
84
 
85
85
  And, then run:
@@ -201,6 +201,49 @@ Output (minified CSS):
201
201
  body{font-size:1.1em;background:white}body > h1{background-color:red;font-size:24px}
202
202
  ```
203
203
 
204
+ ### Raw CSS
205
+
206
+ You can mix in raw CSS with Glimmer CSS DSL syntax by using the `raw` keyword and passing it an argument that is the raw CSS `String`. That enables adding programmability (e.g. `if/else` statements) to some parts of a CSS document while leaving the others as raw CSS.
207
+
208
+ Example (you can try in IRB):
209
+
210
+ ```ruby
211
+ require 'glimmer-dsl-css'
212
+
213
+ include Glimmer
214
+
215
+ color = 'black'
216
+ size = 8
217
+
218
+ @css = css {
219
+ # Programmable CSS
220
+ body {
221
+ font_size size < 10 ? "0.#{size}em" : '1.1em'
222
+ background color.nil? ? 'white' : color
223
+ }
224
+
225
+ # Non-Programmable CSS
226
+ raw '
227
+ body > h1 {
228
+ background-color: red;
229
+ font-size: 24px;
230
+ }
231
+
232
+ body > section {
233
+ font-size: 16px;
234
+ }
235
+ '
236
+ }
237
+
238
+ puts @css
239
+ ```
240
+
241
+ Output (minified CSS):
242
+
243
+ ```css
244
+ body{font-size:0.8em;background:black}body > h1 {background-color: red;font-size: 24px;}body > section {font-size: 16px;}
245
+ ```
246
+
204
247
  ### CSS to Glimmer Converter
205
248
 
206
249
  The Ruby gem includes a CSS to Glimmer converter (`css_to_glimmer`) to automatically convert legacy CSS code into Glimmer DSL syntax.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.1
1
+ 1.5.0
data/bin/minify_css CHANGED
@@ -12,7 +12,7 @@ else
12
12
  css_file_path = ARGV.first
13
13
  puts "Minifying CSS for input file: #{css_file_path}"
14
14
  css = File.read(css_file_path)
15
- converter = Glimmer::CSS::CSSMinifier.new
15
+ converter = Glimmer::CSS::CSSMinifier.instance
16
16
  minified_css = converter.convert(css)
17
17
  minified_css_file_path = "#{File.basename(css_file_path, '.css')}.minified.css"
18
18
  File.write(minified_css_file_path, minified_css)
@@ -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.4.1 ruby lib
5
+ # stub: glimmer-dsl-css 1.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "glimmer-dsl-css".freeze
9
- s.version = "1.4.1"
9
+ s.version = "1.5.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]
@@ -30,11 +30,13 @@ Gem::Specification.new do |s|
30
30
  "bin/minify_css",
31
31
  "glimmer-dsl-css.gemspec",
32
32
  "lib/glimmer-dsl-css.rb",
33
+ "lib/glimmer/css/css_fragment.rb",
34
+ "lib/glimmer/css/css_fragment_composite.rb",
33
35
  "lib/glimmer/css/css_minifier.rb",
34
36
  "lib/glimmer/css/css_to_glimmer_converter.rb",
35
37
  "lib/glimmer/css/media_query.rb",
38
+ "lib/glimmer/css/raw_css.rb",
36
39
  "lib/glimmer/css/rule.rb",
37
- "lib/glimmer/css/rule_composite.rb",
38
40
  "lib/glimmer/css/style_sheet.rb",
39
41
  "lib/glimmer/dsl/css/css_expression.rb",
40
42
  "lib/glimmer/dsl/css/display_expression.rb",
@@ -45,6 +47,7 @@ Gem::Specification.new do |s|
45
47
  "lib/glimmer/dsl/css/media_expression.rb",
46
48
  "lib/glimmer/dsl/css/property_expression.rb",
47
49
  "lib/glimmer/dsl/css/pv_expression.rb",
50
+ "lib/glimmer/dsl/css/raw_expression.rb",
48
51
  "lib/glimmer/dsl/css/ru_expression.rb",
49
52
  "lib/glimmer/dsl/css/rul_expression.rb",
50
53
  "lib/glimmer/dsl/css/rule_expression.rb",
@@ -0,0 +1,36 @@
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
+ module CssFragment
25
+ # Subclasses must override to return a CSS String
26
+ def to_css
27
+ raise 'Not implemented! Subclasses must override/implement to return a CSS String.'
28
+ end
29
+
30
+ # Returns the value of to_css
31
+ def to_s
32
+ to_css
33
+ end
34
+ end
35
+ end
36
+ end
@@ -19,11 +19,19 @@
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/css_fragment'
23
+
22
24
  module Glimmer
23
25
  module CSS
24
- module RuleComposite
25
- def rules
26
- @rules ||= []
26
+ module CssFragmentComposite
27
+ include CssFragment
28
+
29
+ def children
30
+ @children ||= []
31
+ end
32
+
33
+ def to_css
34
+ children.map(&:to_css).join
27
35
  end
28
36
  end
29
37
  end
@@ -19,9 +19,14 @@
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 'singleton'
23
+
22
24
  module Glimmer
23
25
  module CSS
26
+ # A very rudimentary CSS minifier. It does not minify CSS completely at the moment.
24
27
  class CSSMinifier
28
+ include Singleton
29
+
25
30
  def convert(css)
26
31
  css.lines.map(&:chomp).map(&:strip).join
27
32
  end
@@ -48,7 +48,7 @@ module Glimmer
48
48
  end
49
49
 
50
50
  def minify(css)
51
- CSSMinifier.new.convert(css)
51
+ CSSMinifier.instance.convert(css)
52
52
  end
53
53
 
54
54
  def remove_charset(css)
@@ -19,18 +19,16 @@
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'
22
+ require 'glimmer/css/css_fragment_composite'
23
23
  require 'glimmer/css/rule'
24
24
 
25
25
  module Glimmer
26
26
  module CSS
27
27
  class MediaQuery < Rule
28
- include RuleComposite
28
+ include CssFragmentComposite
29
29
 
30
30
  def to_css
31
- css = "@media #{selector}{"
32
- css += rules.map(&:to_css).join
33
- css += "}"
31
+ "@media #{selector}{#{super}}"
34
32
  end
35
33
  end
36
34
  end
@@ -0,0 +1,44 @@
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/css/css_fragment'
23
+ require 'glimmer/css/css_minifier'
24
+
25
+ module Glimmer
26
+ module CSS
27
+ class RawCss
28
+ include CssFragment
29
+
30
+ attr_reader :raw_css_string
31
+
32
+ def initialize(raw_css_string, parent:)
33
+ @raw_css_string = raw_css_string
34
+ @parent = parent
35
+ @minifier = CSSMinifier.instance
36
+ parent.children << self
37
+ end
38
+
39
+ def to_css
40
+ @minifier.convert(@raw_css_string)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -19,16 +19,20 @@
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/css_fragment'
23
+
22
24
  module Glimmer
23
25
  module CSS
24
26
  class Rule
27
+ include CssFragment
28
+
25
29
  attr_reader :selector, :properties
26
30
 
27
31
  def initialize(selector, parent:)
28
32
  @selector = selector
29
33
  @properties = {}
30
34
  @parent = parent
31
- parent.rules << self
35
+ parent.children << self
32
36
  end
33
37
 
34
38
  def add_property(keyword, *args)
@@ -44,8 +48,6 @@ module Glimmer
44
48
  end.join(';')
45
49
  css += "}"
46
50
  end
47
-
48
- alias to_s to_css
49
51
  end
50
52
  end
51
53
  end
@@ -19,19 +19,15 @@
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'
22
+ require 'glimmer/css/css_fragment_composite'
23
23
  require 'glimmer/css/rule'
24
+ require 'glimmer/css/media_query'
25
+ require 'glimmer/css/raw_css'
24
26
 
25
27
  module Glimmer
26
28
  module CSS
27
29
  class StyleSheet
28
- include RuleComposite
29
-
30
- def to_css
31
- rules.map(&:to_css).join
32
- end
33
-
34
- alias to_s to_css
30
+ include CssFragmentComposite
35
31
  end
36
32
  end
37
33
  end
@@ -24,6 +24,7 @@ require 'glimmer/dsl/engine'
24
24
  require 'glimmer/dsl/css/element_rule_expression'
25
25
  require 'glimmer/dsl/css/dynamic_property_expression'
26
26
  require 'glimmer/dsl/css/css_expression'
27
+ require 'glimmer/dsl/css/raw_expression'
27
28
  require 'glimmer/dsl/css/rule_expression'
28
29
  require 'glimmer/dsl/css/rul_expression'
29
30
  require 'glimmer/dsl/css/ru_expression'
@@ -0,0 +1,43 @@
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/css/raw_css'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module CSS
28
+ class RawExpression < StaticExpression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ !block_given? and
31
+ !args.empty? and
32
+ args.size == 1 and
33
+ parent.is_a?(Glimmer::CSS::StyleSheet)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ raw_css_string = args.first
38
+ Glimmer::CSS::RawCss.new(raw_css_string, parent: parent)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
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.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
@@ -228,11 +228,13 @@ files:
228
228
  - bin/minify_css
229
229
  - glimmer-dsl-css.gemspec
230
230
  - lib/glimmer-dsl-css.rb
231
+ - lib/glimmer/css/css_fragment.rb
232
+ - lib/glimmer/css/css_fragment_composite.rb
231
233
  - lib/glimmer/css/css_minifier.rb
232
234
  - lib/glimmer/css/css_to_glimmer_converter.rb
233
235
  - lib/glimmer/css/media_query.rb
236
+ - lib/glimmer/css/raw_css.rb
234
237
  - lib/glimmer/css/rule.rb
235
- - lib/glimmer/css/rule_composite.rb
236
238
  - lib/glimmer/css/style_sheet.rb
237
239
  - lib/glimmer/dsl/css/css_expression.rb
238
240
  - lib/glimmer/dsl/css/display_expression.rb
@@ -243,6 +245,7 @@ files:
243
245
  - lib/glimmer/dsl/css/media_expression.rb
244
246
  - lib/glimmer/dsl/css/property_expression.rb
245
247
  - lib/glimmer/dsl/css/pv_expression.rb
248
+ - lib/glimmer/dsl/css/raw_expression.rb
246
249
  - lib/glimmer/dsl/css/ru_expression.rb
247
250
  - lib/glimmer/dsl/css/rul_expression.rb
248
251
  - lib/glimmer/dsl/css/rule_expression.rb