xrb 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +60 -0
- data/app/helpers/ui_helper.rb +80 -0
- data/app/models/xrb/element.rb +9 -0
- data/lib/xrb/engine.rb +4 -0
- data/rails/init.rb +1 -0
- data/xrb.gemspec +12 -0
- metadata +69 -0
data/README
ADDED
@@ -0,0 +1,60 @@
|
|
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.
|
@@ -0,0 +1,80 @@
|
|
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/lib/xrb/engine.rb
ADDED
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'xrb/engine'
|
data/xrb.gemspec
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Aizat Faiz
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-05 00:00:00 Z
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description:
|
21
|
+
email: aizat.faiz@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- README
|
30
|
+
- app/helpers/ui_helper.rb
|
31
|
+
- app/models/xrb/element.rb
|
32
|
+
- lib/xrb/engine.rb
|
33
|
+
- rails/init.rb
|
34
|
+
- xrb.gemspec
|
35
|
+
homepage: http://github.com/aizatto/xrb
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.7.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: XRB summary
|
68
|
+
test_files: []
|
69
|
+
|