PORTL 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/Rakefile +9 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/portl.rb +22 -0
- data/lib/portl/engine.rb +54 -0
- data/lib/portl/html.rb +22 -0
- data/lib/portl/template.rb +41 -0
- data/lib/portl/version.rb +3 -0
- data/portl.gemspec +36 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eed1f0a92f64b92f9d4b8c17006a383f4ab412bc
|
4
|
+
data.tar.gz: 579e5d84d99d4ea9cae9d174638755fc3596bf27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc58412ba592ce73a58042b7d5ec2df4843665e94dc23548a64be8a79d8b88ff2edcab1479e65c72ddc67de0e81f2465c2fe776d005cabada792af36ffa3836e
|
7
|
+
data.tar.gz: 59e3b6832e255adae4c56745a81090a72537fe20a2d0ee27d24397bbc11404a1a09b34001cfccf21d5e5c942ca6ce75808c3a50cc9ce682519c23066df0f5203
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Travis Haynes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# PORTL
|
2
|
+
|
3
|
+
**Plain Old Ruby Template Language**
|
4
|
+
|
5
|
+
This is a templating language for Rails that uses plain Ruby.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
raw '<!doctype html>'
|
9
|
+
html do
|
10
|
+
head do
|
11
|
+
title 'PORTL Example'
|
12
|
+
meta charset: 'utf-8'
|
13
|
+
end
|
14
|
+
body do
|
15
|
+
div id: 'main' do
|
16
|
+
h1 'Hello world!'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'portl'
|
28
|
+
```
|
29
|
+
|
30
|
+
Then run `bundle` to install.
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
Create a template in your project with the `.rb` extension. For example,
|
35
|
+
`application.html.rb`.
|
36
|
+
|
37
|
+
The syntax for the HTML tags are the same as the `content_tag` view helper.
|
38
|
+
Most HTML5 tags should be supported. For those that aren't, just use
|
39
|
+
`content_tag` directly.
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
44
|
+
`rake test` to run the tests. You can also run `bin/console` for an interactive
|
45
|
+
prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at
|
52
|
+
[https://github.com/hi5dev/portl](https://github.com/hi5dev/portl).
|
53
|
+
|
54
|
+
## License
|
55
|
+
|
56
|
+
The gem is available as open source under the terms of the
|
57
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/portl.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'tilt'
|
3
|
+
|
4
|
+
module PORTL
|
5
|
+
autoload :Engine, 'portl/engine'
|
6
|
+
autoload :HTML, 'portl/html'
|
7
|
+
autoload :Template, 'portl/template'
|
8
|
+
autoload :VERSION, 'portl/version'
|
9
|
+
|
10
|
+
# Compiles a PORTL template.
|
11
|
+
#
|
12
|
+
# @param [String] data The Ruby code of the template being compiled.
|
13
|
+
# @param [Object] scope An object the engine uses for its context.
|
14
|
+
# @param [Hash] options Options to pass to the engine.
|
15
|
+
# @return [String] The compiled code.
|
16
|
+
def self.compile(data, scope=nil, options={})
|
17
|
+
PORTL::Engine.new(data, scope, options).result
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Register the .rb extension with Tilt
|
22
|
+
Tilt.register PORTL::Template, 'rb'
|
data/lib/portl/engine.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
class PORTL::Engine
|
2
|
+
include ActionView::Helpers::TagHelper
|
3
|
+
|
4
|
+
attr_reader :data, :scope, :options
|
5
|
+
|
6
|
+
attr_accessor :output_buffer
|
7
|
+
|
8
|
+
def initialize(data, scope=nil, options={})
|
9
|
+
@data = data
|
10
|
+
@scope = scope
|
11
|
+
@options = options
|
12
|
+
@output_buffer = ActionView::OutputBuffer.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# Compiles the data within the supplied scope and returns the result.
|
16
|
+
#
|
17
|
+
# @return [String] The result of the compiled code.
|
18
|
+
def result
|
19
|
+
eval(data)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates an HTML tag.
|
23
|
+
#
|
24
|
+
# @param [Symbol] tag The tag to generate.
|
25
|
+
# @param [*Array] args Arguments to pass to the Rails `content_tag` helper.
|
26
|
+
# @param [&Proc] block Code to render inside of the tag.
|
27
|
+
# @param [ActionView::OutputBuffer] The updated buffer.
|
28
|
+
def html_tag(tag, *args, &block)
|
29
|
+
if PORTL::HTML::NON_CLOSING_TAGS.include?(tag)
|
30
|
+
output_buffer << raw("<#{tag}#{tag_options(args[0], true)}>")
|
31
|
+
else
|
32
|
+
output_buffer << content_tag(tag, *args, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Adds plain text to the output buffer.
|
37
|
+
#
|
38
|
+
# @param [String] value The text to add.
|
39
|
+
# @return [ActionView::OutputBuffer] The updated buffer.
|
40
|
+
def text(value)
|
41
|
+
output_buffer << raw(value)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# Dynamically create tag generators for all of the supported HTML tags.
|
47
|
+
PORTL::HTML::TAGS.each do |tag|
|
48
|
+
# Do not redefine a method if it already exists.
|
49
|
+
next if methods.include?(tag)
|
50
|
+
|
51
|
+
# Delegate to the #html_tag method, passing the tag as the first argument.
|
52
|
+
define_method(tag) {|*args, &block| html_tag(tag, *args, &block) }
|
53
|
+
end
|
54
|
+
end
|
data/lib/portl/html.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module PORTL
|
2
|
+
module HTML
|
3
|
+
# All of the HTML tags available to the engine.
|
4
|
+
TAGS = %i[
|
5
|
+
a abbr acronym address applet area article aside audio b base
|
6
|
+
basefont bdi bdo big blockquote body br button canvas caption
|
7
|
+
center cite code col colgroup datalist dd del details dfn dialog
|
8
|
+
dir div dl dt em fieldset figcaption figure font footer form frame
|
9
|
+
frameset h1 head header hr html i iframe img input ins kbd keygen
|
10
|
+
label legend li link main map mark menu menuitem meta meter nav
|
11
|
+
noframes noscript object ol optgroup option output p param pre
|
12
|
+
progress q rp rt ruby s samp script section select small source
|
13
|
+
span strike strong style sub summary sup table tbody td textarea
|
14
|
+
tfoot th thead time title tr track tt u ul var video wbr
|
15
|
+
]
|
16
|
+
|
17
|
+
# HTML tags that should not be closed.
|
18
|
+
NON_CLOSING_TAGS = %i[
|
19
|
+
br input meta
|
20
|
+
]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PORTL
|
2
|
+
# @!attribute data
|
3
|
+
# Template source; loaded from a file or given directly.
|
4
|
+
#
|
5
|
+
# @return [String] The content of the template.
|
6
|
+
#
|
7
|
+
# @!attribute file
|
8
|
+
# The name of the file where the template data was loaded from.
|
9
|
+
#
|
10
|
+
# @return [String] Full path to the file.
|
11
|
+
#
|
12
|
+
# @!attribute line
|
13
|
+
# The line number in #file where template data was loaded from.
|
14
|
+
#
|
15
|
+
# @return [Integer] Line number.
|
16
|
+
#
|
17
|
+
# @!attribute options
|
18
|
+
# A Hash of template engine specific options.
|
19
|
+
#
|
20
|
+
# @return [Hash] Options used to compile the template.
|
21
|
+
#
|
22
|
+
class Template < Tilt::Template
|
23
|
+
# Prepares the template. This is called immediately after the data is
|
24
|
+
# loaded. Instance variables set in this method are available to #evaluate
|
25
|
+
# when it is called.
|
26
|
+
#
|
27
|
+
# @note If this isn't overridden an exception will be raised.
|
28
|
+
def prepare
|
29
|
+
# nothing to see here, move along, oh my God, what is this??
|
30
|
+
# huddle around everybody! come closer and take a look at this empty
|
31
|
+
# method.
|
32
|
+
end
|
33
|
+
|
34
|
+
# Execute the compiled template and return the result string. Template
|
35
|
+
# evaluation is guaranteed to be performed in the scope object with the
|
36
|
+
# locals specified and with support for yielding to the block.
|
37
|
+
def evaluate(scope, locals)
|
38
|
+
@output ||= PORTL.compile(data, scope, options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/portl.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require 'portl/version'
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = 'PORTL'
|
11
|
+
spec.version = PORTL::VERSION
|
12
|
+
spec.authors = ['Travis Haynes']
|
13
|
+
spec.email = ['travis@hi5dev.com']
|
14
|
+
|
15
|
+
spec.summary = 'A plain Ruby templating language for Rails.'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |file|
|
19
|
+
file.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^#{spec.bindir}/}) do |file|
|
24
|
+
File.basename(file)
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.require_paths = %w[lib]
|
28
|
+
|
29
|
+
spec.add_dependency 'rails', '>= 4.0.0'
|
30
|
+
spec.add_dependency 'tilt', '~> 2.0.5'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'byebug', '~> 9.0.5'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: PORTL
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Haynes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tilt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 9.0.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 9.0.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- travis@hi5dev.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/portl.rb
|
113
|
+
- lib/portl/engine.rb
|
114
|
+
- lib/portl/html.rb
|
115
|
+
- lib/portl/template.rb
|
116
|
+
- lib/portl/version.rb
|
117
|
+
- portl.gemspec
|
118
|
+
homepage:
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.5.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: A plain Ruby templating language for Rails.
|
142
|
+
test_files: []
|