paggio 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +29 -0
- data/.rspec +2 -0
- data/Gemfile.lock +4 -1
- data/Rakefile +6 -6
- data/lib/paggio/css/definition.rb +1 -1
- data/lib/paggio/css.rb +11 -4
- data/lib/paggio/html/element.rb +1 -1
- data/lib/paggio/html.rb +21 -6
- data/paggio.gemspec +3 -3
- data/spec/html_spec.rb +32 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2fefeb82ee3a488498bd68beb67ff153d799ed90d0048ab6431548af06bae9b3
|
4
|
+
data.tar.gz: b4dad7ad19b3976bb1b92fab92cde617338e4d6e02a777891ed04199bb7a5695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8004f7ba60ad66eae1d64f1be17766f544459aa87b0876bffe3cef9c17997b6dfb16ae96192c33ead174efb146f9b2827245aa3f144b188296bfbb1f95f81a
|
7
|
+
data.tar.gz: f37fab29e7fa8404c2f6adec4b711b3a4b644b691fe40065711501e28b12e9369e7e8a370f6174d45bef8cc233c3ab7683cf2b571b55a92220f53f277120b20f
|
@@ -0,0 +1,29 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
- "*-stable"
|
7
|
+
- "*/ci-check"
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
tests:
|
12
|
+
name: Tests
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby: [2.6, 2.7, 3.0]
|
17
|
+
runs-on: ubuntu-latest
|
18
|
+
steps:
|
19
|
+
- name: Checkout code
|
20
|
+
uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- name: Setup Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
bundler-cache: true
|
27
|
+
|
28
|
+
- name: Run tests
|
29
|
+
run: bundle exec rake
|
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bundler/gem_tasks'
|
2
5
|
require 'rake'
|
3
6
|
|
4
|
-
|
7
|
+
require "rspec/core/rake_task"
|
8
|
+
RSpec::Core::RakeTask.new(:rspec)
|
5
9
|
|
6
|
-
task :
|
7
|
-
FileUtils.cd 'spec' do
|
8
|
-
sh 'rspec css_spec.rb html_spec.rb --backtrace --color --format doc'
|
9
|
-
end
|
10
|
-
end
|
10
|
+
task :default => :rspec
|
@@ -39,7 +39,7 @@ class Definition < BasicObject
|
|
39
39
|
"url(#{value.to_s.inspect})"
|
40
40
|
end
|
41
41
|
|
42
|
-
%w[
|
42
|
+
%w[blur brightness rotate contrast grayscale invert opacity saturate sepia].each {|name|
|
43
43
|
define_method name do |value|
|
44
44
|
"#{name}(#{value})"
|
45
45
|
end
|
data/lib/paggio/css.rb
CHANGED
@@ -38,7 +38,7 @@ class CSS < BasicObject
|
|
38
38
|
|
39
39
|
attr_reader :rules, :media, :fonts, :animations
|
40
40
|
|
41
|
-
def initialize(&block)
|
41
|
+
def initialize(defer: false, &block)
|
42
42
|
::Kernel.raise ::ArgumentError, 'no block given' unless block
|
43
43
|
|
44
44
|
@selector = []
|
@@ -46,12 +46,19 @@ class CSS < BasicObject
|
|
46
46
|
@rules = []
|
47
47
|
@fonts = []
|
48
48
|
@animations = []
|
49
|
+
|
50
|
+
@block = block
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
+
build! unless defer
|
53
|
+
end
|
54
|
+
|
55
|
+
def build!(force_call: false)
|
56
|
+
if !force_call && @block.arity == 0
|
57
|
+
instance_exec(&@block)
|
52
58
|
else
|
53
|
-
block.call(self)
|
59
|
+
@block.call(self)
|
54
60
|
end
|
61
|
+
@block = nil
|
55
62
|
end
|
56
63
|
|
57
64
|
def rule(*names, &block)
|
data/lib/paggio/html/element.rb
CHANGED
data/lib/paggio/html.rb
CHANGED
@@ -16,24 +16,31 @@ class Paggio
|
|
16
16
|
class HTML < BasicObject
|
17
17
|
attr_reader :version
|
18
18
|
|
19
|
-
def initialize(version = 5, &block)
|
19
|
+
def initialize(version = 5, defer: false, &block)
|
20
20
|
::Kernel.raise ::ArgumentError, 'no block given' unless block
|
21
21
|
|
22
22
|
@version = version
|
23
23
|
@roots = []
|
24
24
|
@current = nil
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
block.call(self)
|
30
|
-
end
|
26
|
+
@block = block
|
27
|
+
|
28
|
+
build! unless defer
|
31
29
|
end
|
32
30
|
|
33
31
|
def <<(what)
|
34
32
|
(@current || @roots) << what
|
35
33
|
end
|
36
34
|
|
35
|
+
def build!(force_call: false)
|
36
|
+
if !force_call && @block.arity == 0
|
37
|
+
instance_exec(&@block)
|
38
|
+
else
|
39
|
+
@block.call(self)
|
40
|
+
end
|
41
|
+
@block = nil
|
42
|
+
end
|
43
|
+
|
37
44
|
def root!
|
38
45
|
@roots.first
|
39
46
|
end
|
@@ -64,6 +71,11 @@ class HTML < BasicObject
|
|
64
71
|
@roots.each(&block)
|
65
72
|
end
|
66
73
|
|
74
|
+
def text(*fragments, &block)
|
75
|
+
fragments << yield if block
|
76
|
+
fragments.each { |fragment| self << fragment }
|
77
|
+
end
|
78
|
+
|
67
79
|
def method_missing(name, *args, &block)
|
68
80
|
if name.to_s.end_with? ?!
|
69
81
|
return super
|
@@ -92,6 +104,9 @@ class HTML < BasicObject
|
|
92
104
|
element
|
93
105
|
end
|
94
106
|
|
107
|
+
# Support for custom elements
|
108
|
+
alias e method_missing
|
109
|
+
|
95
110
|
def inspect
|
96
111
|
if @roots.empty?
|
97
112
|
"#<HTML(#@version)>"
|
data/paggio.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new {|s|
|
2
2
|
s.name = 'paggio'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.author = 'meh.'
|
5
5
|
s.email = 'meh@schizofreni.co'
|
6
|
-
s.homepage = 'http://github.com/
|
6
|
+
s.homepage = 'http://github.com/opal/paggio'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = 'Ruby, HTML and CSS at war.'
|
9
|
-
|
9
|
+
s.license = 'WTFPL'
|
10
10
|
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
data/spec/html_spec.rb
CHANGED
@@ -150,4 +150,36 @@ describe Paggio::HTML do
|
|
150
150
|
|
151
151
|
expect(html.to_s).to eq("<i class=\"illegal icon-legal\">\n</i>\n")
|
152
152
|
end
|
153
|
+
|
154
|
+
it 'allows for defered build' do
|
155
|
+
html = Paggio::HTML.new(defer: true) do
|
156
|
+
div
|
157
|
+
end
|
158
|
+
expect(html.roots!.length).to eq(0)
|
159
|
+
|
160
|
+
html.build!
|
161
|
+
expect(html.roots!.length).to eq(1)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'allows for custom elements' do
|
165
|
+
html = Paggio.html! do
|
166
|
+
e('custom-element').test.test!
|
167
|
+
end
|
168
|
+
|
169
|
+
expect(html.to_s).to eq("<custom-element id=\"test\" class=\"test\">\n</custom-element>\n")
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'supports text nodes' do
|
173
|
+
html = Paggio.html! do
|
174
|
+
div {
|
175
|
+
text "test"
|
176
|
+
text { "test" }
|
177
|
+
text "test"
|
178
|
+
div
|
179
|
+
text "test"
|
180
|
+
}
|
181
|
+
end
|
182
|
+
|
183
|
+
expect(html.to_s).to eq("<div>\n\ttest\n\ttest\n\ttest\n\t<div>\n\t</div>\n\ttest\n</div>\n")
|
184
|
+
end
|
153
185
|
end
|
metadata
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paggio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meh.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email: meh@schizofreni.co
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- ".github/workflows/build.yml"
|
20
|
+
- ".rspec"
|
19
21
|
- ".travis.yml"
|
20
22
|
- Gemfile
|
21
23
|
- Gemfile.lock
|
@@ -54,11 +56,11 @@ files:
|
|
54
56
|
- paggio.gemspec
|
55
57
|
- spec/css_spec.rb
|
56
58
|
- spec/html_spec.rb
|
57
|
-
homepage: http://github.com/
|
59
|
+
homepage: http://github.com/opal/paggio
|
58
60
|
licenses:
|
59
61
|
- WTFPL
|
60
62
|
metadata: {}
|
61
|
-
post_install_message:
|
63
|
+
post_install_message:
|
62
64
|
rdoc_options: []
|
63
65
|
require_paths:
|
64
66
|
- lib
|
@@ -73,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
75
|
- !ruby/object:Gem::Version
|
74
76
|
version: '0'
|
75
77
|
requirements: []
|
76
|
-
|
77
|
-
|
78
|
-
signing_key:
|
78
|
+
rubygems_version: 3.2.22
|
79
|
+
signing_key:
|
79
80
|
specification_version: 4
|
80
81
|
summary: Ruby, HTML and CSS at war.
|
81
82
|
test_files:
|