eskimo-html 3.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/eskimo/html/autogen_tags.rb +15 -0
- data/lib/eskimo/html/component.rb +50 -0
- data/lib/eskimo/html/components/autogen.rb +11 -0
- data/lib/eskimo/html/components/html.rb +18 -0
- data/lib/eskimo/html/version.rb +7 -0
- data/lib/eskimo/html.rb +10 -0
- data/spec/component_spec.rb +19 -0
- data/spec/components/autogen_spec.rb +17 -0
- data/spec/components/html_spec.rb +21 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/component_suite.rb +11 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78f0e1ede057ea40c6a5835a1d1aee8b446caf229df59053a89047decb2487d0
|
4
|
+
data.tar.gz: ac55cea304a7ce8510aa28665b633f3e116c1fbea79ea48e232fe8fdc4d89f66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35671025b2a6edd85559678954aa2096fe8506bd9c95d2c1b7a74b9b736216d429c9020f1fd0f30a06fffad86e4efa423ad88fb58184232eb1c1158a33bd51b4
|
7
|
+
data.tar.gz: 495650ce3a7218112af16f5a1cc47df6b7d479a9f2ec11da083c845392c572dce459c5d23691957a1f7525c1af4c58eb9cd6be3349836956e880340d338c00bf
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Eskimo
|
2
|
+
module HTML
|
3
|
+
AUTOGEN_TAGS = %w[
|
4
|
+
a abbr address area article aside audio b base bdi bdo blockquote body
|
5
|
+
br button canvas caption cite code col colgroup data datalist dd del
|
6
|
+
details dfn dialog div dl dt em embed fieldset figcaption figure footer
|
7
|
+
form h1 h2 h3 h4 h5 h6 head header hgroup hr i iframe img input ins kbd
|
8
|
+
keygen label legend li link main map mark math menu menuitem meta meter
|
9
|
+
nav noscript object ol optgroup option output p param picture pre
|
10
|
+
progress q rb rp rt rtc ruby s samp script section select slot small
|
11
|
+
source span strong style sub summary sup svg table tbody td template
|
12
|
+
textarea tfoot th thead time title tr track u ul var video wbr
|
13
|
+
]
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Base HTMLElement component which takes a {tag_name}, a set of {attributes},
|
4
|
+
# and optionally a set of {children} and turns them into a beautiful -- believe
|
5
|
+
# it or not -- HTML tag:
|
6
|
+
#
|
7
|
+
# <x-foo <!-- attributes -->>
|
8
|
+
# <!-- children -->
|
9
|
+
# </x-foo>
|
10
|
+
#
|
11
|
+
# See {ASCII::Component} for how this works under the hood since it's similar.
|
12
|
+
class Eskimo::HTML::Component
|
13
|
+
# Mapping of Ruby attribute name to HTML attribute name; some words like
|
14
|
+
# "class" are reserved and are problematic when passed as attributes so this
|
15
|
+
# hash supports a method to rewrite those.
|
16
|
+
ATTRIBUTE_REWRITES = {
|
17
|
+
'className' => 'class'
|
18
|
+
}
|
19
|
+
|
20
|
+
attr_reader :attributes
|
21
|
+
attr_reader :children
|
22
|
+
attr_reader :tag_name
|
23
|
+
|
24
|
+
def initialize(attributes = {}, &children)
|
25
|
+
@attributes = attributes
|
26
|
+
@children = children
|
27
|
+
end
|
28
|
+
|
29
|
+
def render(render:, **)
|
30
|
+
tag_with_attributes = "#{tag_name} #{serialize_attributes}"
|
31
|
+
|
32
|
+
"<#{tag_with_attributes.strip}>#{render[@children]}</#{tag_name}>"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def serialize_attributes
|
38
|
+
attributes.map do |(k, v)|
|
39
|
+
k = ATTRIBUTE_REWRITES.fetch(k.to_s, k.to_s)
|
40
|
+
|
41
|
+
case v
|
42
|
+
when true
|
43
|
+
"#{k}=\"#{k}\""
|
44
|
+
when false
|
45
|
+
else
|
46
|
+
"#{k}=\"#{v}\""
|
47
|
+
end
|
48
|
+
end.join(' ')
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Eskimo::HTML::Html < Eskimo::HTML::Component
|
4
|
+
def initialize(doctype: 'html', **)
|
5
|
+
@doctype = doctype
|
6
|
+
@tag_name = 'html'
|
7
|
+
super
|
8
|
+
@attributes.delete(:doctype)
|
9
|
+
end
|
10
|
+
|
11
|
+
def render(**)
|
12
|
+
if @doctype.to_s.empty?
|
13
|
+
super
|
14
|
+
else
|
15
|
+
"<!DOCTYPE #{@doctype}>\n" + super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/eskimo/html.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::HTML::Component do
|
6
|
+
it 'accepts a block of children' do
|
7
|
+
class CustomComponent < Eskimo::HTML::Component
|
8
|
+
def tag_name
|
9
|
+
'foo'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
expect(
|
14
|
+
Eskimo::Core::Renderer.new.apply {
|
15
|
+
CustomComponent.new { 'hello world!' }
|
16
|
+
}
|
17
|
+
).to eq("<foo>hello world!</foo>")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::HTML do
|
6
|
+
it 'generates classes for HTML tags' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
Eskimo::HTML::Article.new(className: 'foo') do
|
10
|
+
Eskimo::HTML::P.new do
|
11
|
+
Eskimo::HTML::Span.new { "bar" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
).to eq('<article class="foo"><p><span>bar</span></p></article>')
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Eskimo::HTML::Html do
|
6
|
+
it 'renders the DOCTYPE' do
|
7
|
+
expect(
|
8
|
+
renderer.apply do
|
9
|
+
Eskimo::HTML::Html.new
|
10
|
+
end
|
11
|
+
).to eq("<!DOCTYPE html>\n<html></html>")
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'renders without a DOCTYPE' do
|
15
|
+
expect(
|
16
|
+
renderer.apply do
|
17
|
+
Eskimo::HTML::Html.new(doctype: nil)
|
18
|
+
end
|
19
|
+
).to eq("<html></html>")
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
|
5
|
+
SimpleCov.start do
|
6
|
+
add_filter(%r{/spec/})
|
7
|
+
command_name 'eskimo-html'
|
8
|
+
coverage_dir("#{ENV.fetch('COVERAGE_DIR', 'coverage')}")
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'eskimo/core'
|
12
|
+
require 'eskimo/html'
|
13
|
+
require_relative './support/component_suite'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.expect_with :rspec do |expectations|
|
17
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
18
|
+
end
|
19
|
+
|
20
|
+
config.mock_with :rspec do |mocks|
|
21
|
+
mocks.verify_partial_doubles = true
|
22
|
+
end
|
23
|
+
|
24
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
25
|
+
|
26
|
+
config.filter_run_when_matching :focus
|
27
|
+
|
28
|
+
config.disable_monkey_patching!
|
29
|
+
|
30
|
+
config.warnings = true
|
31
|
+
|
32
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
33
|
+
|
34
|
+
config.order = :random
|
35
|
+
config.define_derived_metadata(file_path: %r{/spec/components/}) do |metadata|
|
36
|
+
metadata[:type] = :component
|
37
|
+
end
|
38
|
+
|
39
|
+
config.include Eskimo::HTML::Test::ComponentSuite, type: :component
|
40
|
+
|
41
|
+
Kernel.srand config.seed
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eskimo-html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ahmad Amireh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eskimo-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.16'
|
55
|
+
description: Render HTML using a declarative, extensible API.
|
56
|
+
email: ahmad@instructure.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/eskimo/html.rb
|
62
|
+
- lib/eskimo/html/autogen_tags.rb
|
63
|
+
- lib/eskimo/html/component.rb
|
64
|
+
- lib/eskimo/html/components/autogen.rb
|
65
|
+
- lib/eskimo/html/components/html.rb
|
66
|
+
- lib/eskimo/html/version.rb
|
67
|
+
- spec/component_spec.rb
|
68
|
+
- spec/components/autogen_spec.rb
|
69
|
+
- spec/components/html_spec.rb
|
70
|
+
- spec/spec_helper.rb
|
71
|
+
- spec/support/component_suite.rb
|
72
|
+
homepage: https://github.com/amireh/eskimo
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.3.1
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.7.6
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Declarative HTML formatting
|
96
|
+
test_files:
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/component_spec.rb
|
99
|
+
- spec/components/autogen_spec.rb
|
100
|
+
- spec/components/html_spec.rb
|
101
|
+
- spec/support/component_suite.rb
|