biruda 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +85 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +23 -0
- data/Gemfile +6 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/TODO.md +2 -0
- data/biruda.gemspec +29 -0
- data/lib/biruda.rb +8 -0
- data/lib/biruda/html.rb +97 -0
- data/lib/biruda/version.rb +3 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8c2ce294cb55eb1708c2bfa852e14b917720fa6
|
4
|
+
data.tar.gz: 8eb765e49c59369a4a993ffd52af9cf347e8bf61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4cc787fe823a104bf18415772e115efbacdbf31db9ab6e3d3df3dbd14c011ef5ffb771b29afb48e4025378e7d635dcd1253678c0c919638d493975d9bd8421e
|
7
|
+
data.tar.gz: b4ca96d2ae904335961e43eed7a09c1a3f1ef032429c65d2cf7322f6f2055e1400ff9d737db8d36ff6c7ad408afb3aa84adca7ead65898a6b8eb940e4f64ccf2
|
data/.gitignore
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
|
14
|
+
# Created by https://www.gitignore.io/api/ruby,osx
|
15
|
+
|
16
|
+
/spec/temp/**/*
|
17
|
+
|
18
|
+
*.log
|
19
|
+
.byebug_history
|
20
|
+
/spec/test_files
|
21
|
+
*.test
|
22
|
+
|
23
|
+
### Ruby ###
|
24
|
+
*.gem
|
25
|
+
*.rbc
|
26
|
+
/.config
|
27
|
+
/coverage/
|
28
|
+
/InstalledFiles
|
29
|
+
/pkg/
|
30
|
+
/spec/reports/
|
31
|
+
/spec/examples.txt
|
32
|
+
/test/tmp/
|
33
|
+
/test/version_tmp/
|
34
|
+
/tmp/
|
35
|
+
|
36
|
+
## Specific to RubyMotion:
|
37
|
+
.dat*
|
38
|
+
.repl_history
|
39
|
+
build/
|
40
|
+
|
41
|
+
## Documentation cache and generated files:
|
42
|
+
/.yardoc/
|
43
|
+
/_yardoc/
|
44
|
+
/doc/
|
45
|
+
/rdoc/
|
46
|
+
|
47
|
+
## Environment normalisation:
|
48
|
+
/.bundle/
|
49
|
+
/vendor/bundle
|
50
|
+
/lib/bundler/man/
|
51
|
+
|
52
|
+
# for a library or gem, you might want to ignore these files since the code is
|
53
|
+
# intended to run in multiple environments; otherwise, check them in:
|
54
|
+
Gemfile.lock
|
55
|
+
.ruby-version
|
56
|
+
.ruby-gemset
|
57
|
+
|
58
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
59
|
+
.rvmrc
|
60
|
+
|
61
|
+
### OSX ###
|
62
|
+
.DS_Store
|
63
|
+
.AppleDouble
|
64
|
+
.LSOverride
|
65
|
+
|
66
|
+
# Icon must end with two \r
|
67
|
+
Icon
|
68
|
+
|
69
|
+
# Thumbnails
|
70
|
+
._*
|
71
|
+
|
72
|
+
# Files that might appear in the root of a volume
|
73
|
+
.DocumentRevisions-V100
|
74
|
+
.fseventsd
|
75
|
+
.Spotlight-V100
|
76
|
+
.TemporaryItems
|
77
|
+
.Trashes
|
78
|
+
.VolumeIcon.icns
|
79
|
+
|
80
|
+
# Directories potentially created on remote AFP share
|
81
|
+
.AppleDB
|
82
|
+
.AppleDesktop
|
83
|
+
Network Trash Folder
|
84
|
+
Temporary Items
|
85
|
+
.apdisk
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- dictum.gemspec
|
4
|
+
- lib/tasks/dictum.rake
|
5
|
+
- spec/spec_helper.rb
|
6
|
+
|
7
|
+
Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
LineLength:
|
11
|
+
Max: 99
|
12
|
+
|
13
|
+
FrozenStringLiteralComment:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/AbcSize:
|
17
|
+
Max: 15.3
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
sudo: false
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3.3
|
8
|
+
|
9
|
+
install:
|
10
|
+
- gem install bundler -v 1.15.3
|
11
|
+
- bundle install --retry=3
|
12
|
+
|
13
|
+
script:
|
14
|
+
- bundle exec rspec
|
15
|
+
- bundle exec rubocop -R lib spec --format simple
|
16
|
+
|
17
|
+
addons:
|
18
|
+
code_climate:
|
19
|
+
repo_token: nil
|
20
|
+
|
21
|
+
os:
|
22
|
+
- linux
|
23
|
+
- osx
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Biruda
|
2
|
+
|
3
|
+
Biruda is a simple DSL to build HTML documents.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'biruda'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install biruda
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
page = Biruda.create_html do
|
25
|
+
head do
|
26
|
+
title 'This is a Biruda HTML DSL test'
|
27
|
+
script src: 'mypage.com/mysuper.js'
|
28
|
+
end
|
29
|
+
body do
|
30
|
+
h1 'HEADING'
|
31
|
+
p [
|
32
|
+
'This is part of my ',
|
33
|
+
-> { b 'paragraph' },
|
34
|
+
', amazing.'
|
35
|
+
]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
puts page
|
40
|
+
```
|
41
|
+
|
42
|
+
This will print:
|
43
|
+
|
44
|
+
```
|
45
|
+
<!DOCTYPE html>
|
46
|
+
<html>
|
47
|
+
<head>
|
48
|
+
<title>This is a Biruda HTML DSL test</title>
|
49
|
+
<script src="mypage.com/mysuper.js" />
|
50
|
+
</head>
|
51
|
+
<body>
|
52
|
+
<h1>HEADING</h1>
|
53
|
+
<p>
|
54
|
+
This is part of my <b>paragraph</b>, amazing.
|
55
|
+
</p>
|
56
|
+
</body>
|
57
|
+
</html>'
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Run rubocop lint (`rubocop -R lib spec --format simple`)
|
66
|
+
5. Run rspec tests (`bundle exec rspec`)
|
67
|
+
6. Push your branch (`git push origin my-new-feature`)
|
68
|
+
7. Create a new Pull Request
|
data/Rakefile
ADDED
data/TODO.md
ADDED
data/biruda.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'biruda/version'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "biruda"
|
9
|
+
spec.version = Biruda::VERSION
|
10
|
+
spec.authors = ['Alejandro Bezdjian']
|
11
|
+
spec.email = ['alebezdjian@gmail.com']
|
12
|
+
spec.date = Date.today
|
13
|
+
spec.summary = 'Simple DSL to build HTML documents'
|
14
|
+
spec.description = 'Simple DSL to build HTML documents'
|
15
|
+
spec.homepage = 'https://github.com/alebian/biruda'
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
spec.license = 'MIT'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
25
|
+
spec.add_development_dependency 'byebug', '~> 9.1'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.51'
|
27
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.15'
|
29
|
+
end
|
data/lib/biruda.rb
ADDED
data/lib/biruda/html.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
module Biruda
|
2
|
+
class HTML
|
3
|
+
# The default HTML version of this class is 5
|
4
|
+
EMPTY_TAG_CLOSER = ' />'.freeze
|
5
|
+
VALID_TAGS = %i[
|
6
|
+
head title body a abbr acronym address applet area article aside audio b base basefont bdi
|
7
|
+
bdo big blockquote br button canvas caption center cite code col colgroup datalist dd del
|
8
|
+
details dfn dialog dir div dl dt em embed fieldset figcaption figure font footer form frame
|
9
|
+
frameset h1 header hr html i iframe img input ins kbd label legend li link main map mark menu
|
10
|
+
menuitem meta meter nav noframes noscript object ol optgroup option output p param pre
|
11
|
+
progress q rp rt ruby s samp script section select small source span strike strong style sub
|
12
|
+
summary sup table tbody td textarea tfoot th thead time tr track tt u ul var video wbr p
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@page = '<!DOCTYPE html>'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(&block)
|
20
|
+
new.build(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
@page
|
25
|
+
end
|
26
|
+
|
27
|
+
def build(&block)
|
28
|
+
html(&block)
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_tag
|
33
|
+
yield
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
VALID_TAGS.each do |tag|
|
40
|
+
define_method(tag) do |*args, &block|
|
41
|
+
tag(tag, *args, &block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
OpeningTag = Struct.new(:tag, :ending?)
|
46
|
+
|
47
|
+
def built_tag_is_empty(name, content, attributes, block_given)
|
48
|
+
opening_tag = "<#{name}"
|
49
|
+
|
50
|
+
attributes.each { |key, value| opening_tag << " #{key}=\"#{value}\"" }
|
51
|
+
|
52
|
+
opening_tag << if content.nil? && !block_given
|
53
|
+
EMPTY_TAG_CLOSER
|
54
|
+
else
|
55
|
+
'>'
|
56
|
+
end
|
57
|
+
|
58
|
+
@page << opening_tag
|
59
|
+
opening_tag.include?(EMPTY_TAG_CLOSER)
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_array_elements(array)
|
63
|
+
array.each do |cont|
|
64
|
+
# This is a workaround because Ruby does not have lazy evaluation, so if the caller sends
|
65
|
+
# a block with an element that is a tag, it will be evaluated before calling the method,
|
66
|
+
# and will add that tag before the rest of the elements in the array
|
67
|
+
if cont.respond_to?(:call)
|
68
|
+
cont.call
|
69
|
+
else
|
70
|
+
@page << cont
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def tag(name, content = nil, attributes = {}, &block)
|
76
|
+
content, attributes = adapt_tag_params(content, attributes)
|
77
|
+
|
78
|
+
return if built_tag_is_empty(name, content, attributes, block_given?)
|
79
|
+
|
80
|
+
if content.is_a?(Array)
|
81
|
+
build_array_elements(content)
|
82
|
+
elsif block_given?
|
83
|
+
instance_eval(&block)
|
84
|
+
else
|
85
|
+
@page << content
|
86
|
+
end
|
87
|
+
|
88
|
+
@page << "</#{name}>"
|
89
|
+
end
|
90
|
+
|
91
|
+
def adapt_tag_params(content, attributes)
|
92
|
+
# In case the caller does something like `script src: 'some js'`
|
93
|
+
return [nil, content] if content.is_a?(Hash)
|
94
|
+
[content, attributes]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: biruda
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alejandro Bezdjian
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '9.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '9.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.51'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.51'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.15'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.15'
|
111
|
+
description: Simple DSL to build HTML documents
|
112
|
+
email:
|
113
|
+
- alebezdjian@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- TODO.md
|
126
|
+
- biruda.gemspec
|
127
|
+
- lib/biruda.rb
|
128
|
+
- lib/biruda/html.rb
|
129
|
+
- lib/biruda/version.rb
|
130
|
+
homepage: https://github.com/alebian/biruda
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.5.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Simple DSL to build HTML documents
|
154
|
+
test_files: []
|