xrb 0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/bake/xrb/entities.rb +60 -0
- data/bake/xrb/parsers.rb +69 -0
- data/ext/extconf.rb +21 -0
- data/ext/xrb/escape.c +152 -0
- data/ext/xrb/escape.h +15 -0
- data/ext/xrb/markup.c +1949 -0
- data/ext/xrb/markup.h +6 -0
- data/ext/xrb/markup.rl +226 -0
- data/ext/xrb/query.c +619 -0
- data/ext/xrb/query.h +6 -0
- data/ext/xrb/query.rl +82 -0
- data/ext/xrb/tag.c +204 -0
- data/ext/xrb/tag.h +21 -0
- data/ext/xrb/template.c +1114 -0
- data/ext/xrb/template.h +6 -0
- data/ext/xrb/template.rl +77 -0
- data/ext/xrb/xrb.c +72 -0
- data/ext/xrb/xrb.h +132 -0
- data/lib/xrb/buffer.rb +103 -0
- data/lib/xrb/builder.rb +222 -0
- data/lib/xrb/entities.rb +2137 -0
- data/lib/xrb/entities.xrb +30 -0
- data/lib/xrb/error.rb +81 -0
- data/lib/xrb/fallback/markup.rb +1658 -0
- data/lib/xrb/fallback/markup.rl +228 -0
- data/lib/xrb/fallback/query.rb +548 -0
- data/lib/xrb/fallback/query.rl +88 -0
- data/lib/xrb/fallback/template.rb +829 -0
- data/lib/xrb/fallback/template.rl +80 -0
- data/lib/xrb/markup.rb +56 -0
- data/lib/xrb/native.rb +15 -0
- data/lib/xrb/parse_delegate.rb +19 -0
- data/lib/xrb/parsers.rb +17 -0
- data/lib/xrb/query.rb +80 -0
- data/lib/xrb/reference.rb +108 -0
- data/lib/xrb/strings.rb +47 -0
- data/lib/xrb/tag.rb +115 -0
- data/lib/xrb/template.rb +164 -0
- data/lib/xrb/uri.rb +100 -0
- data/lib/xrb/version.rb +8 -0
- data/lib/xrb.rb +11 -0
- data/license.md +23 -0
- data/readme.md +29 -0
- data.tar.gz.sig +0 -0
- metadata +109 -58
- metadata.gz.sig +0 -0
- data/README +0 -60
- data/app/helpers/ui_helper.rb +0 -80
- data/app/models/xrb/element.rb +0 -9
- data/lib/xrb/engine.rb +0 -4
- data/rails/init.rb +0 -1
- data/xrb.gemspec +0 -12
data/lib/xrb/uri.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2017-2024, by Samuel Williams.
|
5
|
+
|
6
|
+
module XRB
|
7
|
+
# This class is superceeded by `XRB::Reference`.
|
8
|
+
class URI
|
9
|
+
def initialize(path, query_string, fragment, parameters)
|
10
|
+
@path = path
|
11
|
+
@query_string = query_string
|
12
|
+
@fragment = fragment
|
13
|
+
@parameters = parameters
|
14
|
+
end
|
15
|
+
|
16
|
+
# The path component of the URI, e.g. /foo/bar/index.html
|
17
|
+
attr :path
|
18
|
+
|
19
|
+
# The un-parsed query string of the URI, e.g. 'x=10&y=20'
|
20
|
+
attr :query_string
|
21
|
+
|
22
|
+
# A fragment identifier, the part after the '#'
|
23
|
+
attr :fragment
|
24
|
+
|
25
|
+
# User supplied parameters that will be appended to the query part.
|
26
|
+
attr :parameters
|
27
|
+
|
28
|
+
def append(buffer)
|
29
|
+
if @query_string
|
30
|
+
buffer << escape_path(@path) << '?' << query_string
|
31
|
+
buffer << '&' << query_parameters if @parameters
|
32
|
+
else
|
33
|
+
buffer << escape_path(@path)
|
34
|
+
buffer << '?' << query_parameters if @parameters
|
35
|
+
end
|
36
|
+
|
37
|
+
if @fragment
|
38
|
+
buffer << '#' << escape(@fragment)
|
39
|
+
end
|
40
|
+
|
41
|
+
return buffer
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_str
|
45
|
+
append(String.new)
|
46
|
+
end
|
47
|
+
|
48
|
+
alias to_s to_str
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# According to https://tools.ietf.org/html/rfc3986#section-3.3, we escape non-pchar.
|
53
|
+
NON_PCHAR = /([^a-zA-Z0-9_\-\.~!$&'()*+,;=:@\/]+)/.freeze
|
54
|
+
|
55
|
+
def escape_path(path)
|
56
|
+
encoding = path.encoding
|
57
|
+
path.b.gsub(NON_PCHAR) do |m|
|
58
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
59
|
+
end.force_encoding(encoding)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Escapes a generic string, using percent encoding.
|
63
|
+
def escape(string)
|
64
|
+
encoding = string.encoding
|
65
|
+
string.b.gsub(/([^a-zA-Z0-9_.\-]+)/) do |m|
|
66
|
+
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
67
|
+
end.force_encoding(encoding)
|
68
|
+
end
|
69
|
+
|
70
|
+
def query_parameters
|
71
|
+
build_nested_query(@parameters)
|
72
|
+
end
|
73
|
+
|
74
|
+
def build_nested_query(value, prefix = nil)
|
75
|
+
case value
|
76
|
+
when Array
|
77
|
+
value.map { |v|
|
78
|
+
build_nested_query(v, "#{prefix}[]")
|
79
|
+
}.join("&")
|
80
|
+
when Hash
|
81
|
+
value.map { |k, v|
|
82
|
+
build_nested_query(v, prefix ? "#{prefix}[#{escape(k.to_s)}]" : escape(k.to_s))
|
83
|
+
}.reject(&:empty?).join('&')
|
84
|
+
when nil
|
85
|
+
prefix
|
86
|
+
else
|
87
|
+
raise ArgumentError, "value must be a Hash" if prefix.nil?
|
88
|
+
"#{prefix}=#{escape(value.to_s)}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Generate a URI from a path and user parameters. The path may contain a `#fragment` or `?query=parameters`.
|
94
|
+
def self.URI(path = '', parameters = nil)
|
95
|
+
base, fragment = path.split('#', 2)
|
96
|
+
path, query_string = base.split('?', 2)
|
97
|
+
|
98
|
+
URI.new(path, query_string, fragment, parameters)
|
99
|
+
end
|
100
|
+
end
|
data/lib/xrb/version.rb
ADDED
data/lib/xrb.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2012-2024, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative 'xrb/version'
|
7
|
+
require_relative 'xrb/native'
|
8
|
+
require_relative 'xrb/builder'
|
9
|
+
require_relative 'xrb/template'
|
10
|
+
|
11
|
+
require_relative 'xrb/reference'
|
data/license.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright, 2012-2024, by Samuel Williams.
|
4
|
+
Copyright, 2020, by Cyril Roelandt.
|
5
|
+
Copyright, 2022, by Adam Daniels.
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
9
|
+
in the Software without restriction, including without limitation the rights
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
12
|
+
furnished to do so, subject to the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
15
|
+
copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
23
|
+
SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# XRB
|
2
|
+
|
3
|
+
XRB is a templating system built loosely on top of XHTML markup. It uses efficient native parsers where possible and compiles templates into efficient Ruby. It also includes a markup builder to assist with the generation of pleasantly formatted markup which is compatible with the included parsers.
|
4
|
+
|
5
|
+
[![Development Status](https://github.com/socketry/xrb/workflows/Test/badge.svg)](https://github.com/socketry/xrb/actions?workflow=Test)
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
## See Also
|
10
|
+
|
11
|
+
- [xrb-vscode](https://github.com/socketry/xrb-vscode) package for Visual Studio Code.
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
We welcome contributions to this project.
|
16
|
+
|
17
|
+
1. Fork it.
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`).
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`).
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`).
|
21
|
+
5. Create new Pull Request.
|
22
|
+
|
23
|
+
### Developer Certificate of Origin
|
24
|
+
|
25
|
+
This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
|
26
|
+
|
27
|
+
### Contributor Covenant
|
28
|
+
|
29
|
+
This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,69 +1,120 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: xrb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: "0.1"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
13
|
-
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
- Adam Daniels
|
9
|
+
- Cyril Roelandt
|
10
|
+
autorequire:
|
14
11
|
bindir: bin
|
15
|
-
cert_chain:
|
16
|
-
|
17
|
-
|
12
|
+
cert_chain:
|
13
|
+
- |
|
14
|
+
-----BEGIN CERTIFICATE-----
|
15
|
+
MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
|
16
|
+
ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
|
17
|
+
CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
|
18
|
+
MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
|
19
|
+
MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
|
20
|
+
bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
|
21
|
+
igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
|
22
|
+
9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
|
23
|
+
sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
|
24
|
+
e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
|
25
|
+
XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
|
26
|
+
RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
|
27
|
+
tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
|
28
|
+
zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
|
29
|
+
xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
30
|
+
BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
|
31
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
|
32
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
|
33
|
+
cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
|
34
|
+
xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
|
35
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
36
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
37
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
38
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
39
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
40
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
41
|
+
-----END CERTIFICATE-----
|
42
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
18
43
|
dependencies: []
|
19
|
-
|
20
|
-
|
21
|
-
email: aizat.faiz@gmail.com
|
44
|
+
description:
|
45
|
+
email:
|
22
46
|
executables: []
|
23
|
-
|
24
|
-
|
25
|
-
|
47
|
+
extensions:
|
48
|
+
- ext/extconf.rb
|
26
49
|
extra_rdoc_files: []
|
27
|
-
|
28
|
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
-
|
33
|
-
-
|
34
|
-
- xrb.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
-
|
41
|
-
|
50
|
+
files:
|
51
|
+
- bake/xrb/entities.rb
|
52
|
+
- bake/xrb/parsers.rb
|
53
|
+
- ext/extconf.rb
|
54
|
+
- ext/xrb/escape.c
|
55
|
+
- ext/xrb/escape.h
|
56
|
+
- ext/xrb/markup.c
|
57
|
+
- ext/xrb/markup.h
|
58
|
+
- ext/xrb/markup.rl
|
59
|
+
- ext/xrb/query.c
|
60
|
+
- ext/xrb/query.h
|
61
|
+
- ext/xrb/query.rl
|
62
|
+
- ext/xrb/tag.c
|
63
|
+
- ext/xrb/tag.h
|
64
|
+
- ext/xrb/template.c
|
65
|
+
- ext/xrb/template.h
|
66
|
+
- ext/xrb/template.rl
|
67
|
+
- ext/xrb/xrb.c
|
68
|
+
- ext/xrb/xrb.h
|
69
|
+
- lib/xrb.rb
|
70
|
+
- lib/xrb/buffer.rb
|
71
|
+
- lib/xrb/builder.rb
|
72
|
+
- lib/xrb/entities.rb
|
73
|
+
- lib/xrb/entities.xrb
|
74
|
+
- lib/xrb/error.rb
|
75
|
+
- lib/xrb/fallback/markup.rb
|
76
|
+
- lib/xrb/fallback/markup.rl
|
77
|
+
- lib/xrb/fallback/query.rb
|
78
|
+
- lib/xrb/fallback/query.rl
|
79
|
+
- lib/xrb/fallback/template.rb
|
80
|
+
- lib/xrb/fallback/template.rl
|
81
|
+
- lib/xrb/markup.rb
|
82
|
+
- lib/xrb/native.rb
|
83
|
+
- lib/xrb/parse_delegate.rb
|
84
|
+
- lib/xrb/parsers.rb
|
85
|
+
- lib/xrb/query.rb
|
86
|
+
- lib/xrb/reference.rb
|
87
|
+
- lib/xrb/strings.rb
|
88
|
+
- lib/xrb/tag.rb
|
89
|
+
- lib/xrb/template.rb
|
90
|
+
- lib/xrb/uri.rb
|
91
|
+
- lib/xrb/version.rb
|
92
|
+
- license.md
|
93
|
+
- readme.md
|
94
|
+
homepage: https://github.com/ioquatix/xrb
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
documentation_uri: https://socketry.github.io/xrb/
|
99
|
+
funding_uri: https://github.com/sponsors/ioquatix
|
100
|
+
source_code_uri: https://github.com/ioquatix/xrb.git
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
42
104
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
|
45
|
-
requirements:
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
46
107
|
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
version: "0"
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '3.1'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
55
112
|
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
61
115
|
requirements: []
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
specification_version: 3
|
67
|
-
summary: XRB summary
|
116
|
+
rubygems_version: 3.5.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A fast native templating system that compiles directly to Ruby code.
|
68
120
|
test_files: []
|
69
|
-
|
metadata.gz.sig
ADDED
Binary file
|
data/README
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
XRB was inspired by XHP ( http://github.com/facebook/xhp/ ).
|
2
|
-
XRB is a Rails Engine to be used.
|
3
|
-
|
4
|
-
Having used XHP intensively, I saw the benefits of XML literals as first class
|
5
|
-
elements in a programming language. The biggest benefit was that you could
|
6
|
-
easily build large libraries of components to reuse on many sites.
|
7
|
-
|
8
|
-
As I was unable to figure out how to add XML literals into the Ruby parser.
|
9
|
-
I thought I would start with a more Ruby approach.
|
10
|
-
|
11
|
-
Installation
|
12
|
-
============
|
13
|
-
|
14
|
-
Edit Your Application's Gemfile
|
15
|
-
-------------------------------
|
16
|
-
|
17
|
-
Add to your Gemfile
|
18
|
-
|
19
|
-
gem 'xrb', :require => 'xrb/engine'
|
20
|
-
|
21
|
-
In your ApplicationHelper add
|
22
|
-
|
23
|
-
require UiHelper
|
24
|
-
|
25
|
-
Usage
|
26
|
-
=====
|
27
|
-
|
28
|
-
Inside your template files you can now use XRB.
|
29
|
-
|
30
|
-
<%= ui :image, :block do %>
|
31
|
-
<% ui :link => user_path(user) %>
|
32
|
-
<%= image_tag(user.photo.url(:thumbnail), :title => user %>
|
33
|
-
<% end %>
|
34
|
-
<% ui :group do %>
|
35
|
-
<% ui :link => user_path(user) %>
|
36
|
-
<%= user %>
|
37
|
-
<% end %>
|
38
|
-
<% ui :group do %>
|
39
|
-
<%= user.description %>
|
40
|
-
<% end %>
|
41
|
-
<% end %>
|
42
|
-
<% end %>
|
43
|
-
|
44
|
-
|
45
|
-
Defining your own XRB Element
|
46
|
-
-----------------------------
|
47
|
-
|
48
|
-
Say you want to define an element `user`.
|
49
|
-
Inside a helper file we need to add a function:
|
50
|
-
|
51
|
-
def ui_user(xrb)
|
52
|
-
user = xrb.attributes.delete(:user)
|
53
|
-
|
54
|
-
xrb.content = ui_output do
|
55
|
-
content_tag :div, user, xrb.attributes
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Change the code inside `ui_output` to let design how your component will look
|
60
|
-
like.
|
data/app/helpers/ui_helper.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
module UiHelper
|
2
|
-
|
3
|
-
def ui(*args, &block)
|
4
|
-
component = []
|
5
|
-
if args.length == 1 && args.first.is_a?(Hash) && args.first.length == 1
|
6
|
-
component << args.first.keys.first
|
7
|
-
else
|
8
|
-
while args.first.is_a? Symbol
|
9
|
-
component << args.shift
|
10
|
-
end
|
11
|
-
end
|
12
|
-
component = "ui_#{component.join '_'}"
|
13
|
-
xrb = ui_capture(*args, &block)
|
14
|
-
@components << xrb if @components
|
15
|
-
|
16
|
-
self.send(component, xrb)
|
17
|
-
end
|
18
|
-
|
19
|
-
def ui_image_block(xrb)
|
20
|
-
image = xrb.components.shift
|
21
|
-
group = xrb.components.shift
|
22
|
-
|
23
|
-
title = group.components.shift
|
24
|
-
contents = group.components.shift
|
25
|
-
|
26
|
-
ui_output do <<-HTML
|
27
|
-
<div class="image-block">
|
28
|
-
<div class="image">#{image}</div>
|
29
|
-
<div class="content">
|
30
|
-
<div class="title">#{title}</div>
|
31
|
-
#{contents}
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
<div class="clear"></div>
|
35
|
-
HTML
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def ui_link(xrb)
|
40
|
-
xrb.attributes[:href] = xrb.attributes[:link] if xrb.attributes[:link]
|
41
|
-
|
42
|
-
xrb.content = ui_output do
|
43
|
-
content_tag(:a, xrb.inner_content, xrb.attributes)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def ui_group(xrb)
|
48
|
-
xrb.content = ui_output do
|
49
|
-
xrb.inner_content
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# helper
|
54
|
-
def ui_output
|
55
|
-
value = yield
|
56
|
-
|
57
|
-
value.html_safe
|
58
|
-
end
|
59
|
-
|
60
|
-
def ui_capture(*args, &block)
|
61
|
-
xrb = ::XRB::Element.new
|
62
|
-
xrb.attributes = args.extract_options!
|
63
|
-
|
64
|
-
if block
|
65
|
-
@components, old_components = [], @components
|
66
|
-
xrb.inner_content = capture(&block)
|
67
|
-
xrb.components = @components
|
68
|
-
@components = old_components
|
69
|
-
else
|
70
|
-
xrb.inner_content = args.first || ''
|
71
|
-
end
|
72
|
-
|
73
|
-
if xrb.inner_content.is_a?(String) && ! xrb.inner_content.html_safe?
|
74
|
-
xrb.inner_content = xrb.inner_content.html_safe
|
75
|
-
end
|
76
|
-
|
77
|
-
xrb
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/app/models/xrb/element.rb
DELETED
data/lib/xrb/engine.rb
DELETED
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'xrb/engine'
|
data/xrb.gemspec
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = %q{xrb}
|
3
|
-
s.version = "0.1"
|
4
|
-
s.authors = ["Aizat Faiz"]
|
5
|
-
s.email = %q{aizat.faiz@gmail.com}
|
6
|
-
s.date = Time.now.utc.strftime("%Y-%m-%d")
|
7
|
-
s.files = `git ls-files`.split("\n")
|
8
|
-
s.homepage = %q{http://github.com/aizatto/xrb}
|
9
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
10
|
-
s.rubygems_version = %q{1.7.2}
|
11
|
-
s.summary = %q{XRB summary}
|
12
|
-
end
|