txprails 0.1.1 → 0.1.2
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.
- data/README.rdoc +47 -9
- data/VERSION +1 -1
- data/lib/txprails.rb +52 -1
- data/lib/txprails/template.rb +3 -2
- data/txprails.gemspec +2 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
= TXPRrails
|
2
2
|
|
3
|
-
*DISCLAIMER
|
3
|
+
*DISCLAIMER*
|
4
4
|
|
5
|
-
TXPRails born kind of
|
6
|
-
progress.
|
5
|
+
TXPRails was born kind of an experiment. Please be aware that this is a work
|
6
|
+
in progress.
|
7
7
|
|
8
|
-
= TXPRails =
|
8
|
+
= TXPRails = Textpattern Rails
|
9
9
|
|
10
|
-
This gem is
|
10
|
+
This gem is an experiment for using *Textpattern* like templates in a Rails
|
11
11
|
environment. Rails have many template engines available, from ERB thru Haml,
|
12
12
|
etc. However, for many of us from a more traditional PHP/like environment,
|
13
|
-
XML-style templates seems more natural. Moreover,
|
13
|
+
XML-style templates seems more natural. Moreover, TXP style templates differ
|
14
14
|
from Haml or ERB in one thing: the templates are not "compiled" in the sense
|
15
15
|
of making 1 pre-compile pass (Haml) or more-or-less-directly ruby-executed
|
16
|
-
(ERB).
|
16
|
+
(ERB). TXP templates are executed while parsing, using different techniques
|
17
17
|
explained below.
|
18
18
|
|
19
19
|
I think Haml is kind of awesome, and I'm slowly getting used to it. However,
|
20
20
|
I'm still fascinated of the elegance and simplicity of TXP XML'ish templates.
|
21
|
+
Liquid template fans will also find TXP templates very easy to use.
|
21
22
|
|
22
23
|
So, in essence, I started this project solely for this pourposes:
|
23
24
|
|
@@ -28,9 +29,46 @@ So, in essence, I started this project solely for this pourposes:
|
|
28
29
|
* Just for fun... :-)
|
29
30
|
|
30
31
|
*This project and some of the code (namely the Rails plugin bootstrap) is
|
31
|
-
heavily inspired by Haml itself
|
32
|
+
heavily inspired by Haml itself*. Also, there is also some influence of the
|
33
|
+
*fluid* template engine.
|
32
34
|
|
33
|
-
Please, PLEASE, if you find this gem useful, comment and make suggestions to
|
35
|
+
Please, PLEASE, if you find this gem useful, comment and make suggestions to
|
36
|
+
make it better. I think you may also benefit and learn from TXPRails.
|
37
|
+
|
38
|
+
|
39
|
+
= EXAMPLES
|
40
|
+
|
41
|
+
TextPattern syntax templates have an extension of +.txp+, you can rename all
|
42
|
+
your templates to use +.txp* extension and will use TXPRails as template
|
43
|
+
engine.
|
44
|
+
|
45
|
+
Please, read the {manual for Textpattern tags}[http://textpattern.net/wiki/index.php?title=Tag_Basics]
|
46
|
+
to get the basics.
|
47
|
+
|
48
|
+
Textpattern tags are XML. There are two kind of tags: Self referenced and
|
49
|
+
container tags. Self referenced tags are XML self-closed tags like
|
50
|
+
+<txp:content />+. Container tags, on the other hand, have a block of text
|
51
|
+
between the the tag pair like: +<txp:link to="destination"> ...blah,
|
52
|
+
blah...</txp:link>+.
|
53
|
+
|
54
|
+
Pay close attention to self-closed tags. They have a forward slash at the end,
|
55
|
+
exactly like XHTML tags.
|
56
|
+
|
57
|
+
Textpattern tags have a "domain" and "name" part, like this: +<domain:name />+. The Domain part plays an important role in TXPRails, unlike in
|
58
|
+
Textpattern where they are simply "sintactic sugar".
|
59
|
+
|
60
|
+
= Differences from Textpattern
|
61
|
+
|
62
|
+
Template Tags in the Textpattern publishing system are very tight coupled. For
|
63
|
+
example, tags like +<txp:permlink />+ requires to have a blog, a post and this
|
64
|
+
post have a permalink. This is not the case with TXPRails, in which we
|
65
|
+
obviously haven't a blog. In Rails we have Models:
|
66
|
+
|
67
|
+
<mod:clients limit="5">
|
68
|
+
The name: <var:name /><br />
|
69
|
+
The phone: <var:phone /><br />
|
70
|
+
<txp:link>View more</txp:link>
|
71
|
+
</mod:clients>
|
34
72
|
|
35
73
|
|
36
74
|
== Note on Patches/Pull Requests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/txprails.rb
CHANGED
@@ -36,9 +36,60 @@ module TXP
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def txp_eval(tag)
|
40
|
+
eval(tag.attr["code"])
|
41
|
+
end
|
42
|
+
|
39
43
|
def txp_include(tag)
|
40
44
|
@view.render :partial => tag.attr["name"]
|
41
45
|
end
|
42
46
|
|
43
|
-
|
47
|
+
def txp_controller(tag)
|
48
|
+
@view.controller.instance_variable_names.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def method_missing(method_id, *args, &block)
|
53
|
+
method_name = method_id.to_s
|
54
|
+
super if method_name !~ /^mod_/ && method_name !~ /^var_/
|
55
|
+
|
56
|
+
# Model or variable requested...
|
57
|
+
tag = args.first
|
58
|
+
output = []
|
59
|
+
case method_name
|
60
|
+
when /^mod_/
|
61
|
+
if @_current_models.empty? || @_current_var.nil?
|
62
|
+
variables = @view.controller.instance_variable_names
|
63
|
+
variables -= @view.controller.protected_instance_variables if @view.controller.respond_to?(:protected_instance_variables)
|
64
|
+
raise "Model not found" unless variables.include?("@#{tag.name}")
|
65
|
+
@_current_models.push(@view.controller.instance_variable_get("@#{tag.name}"))
|
66
|
+
else
|
67
|
+
raise "Model not found in current model" unless @_current_var.respond_to?(tag.name.to_sym)
|
68
|
+
@_current_models.push(@_current_var.send(tag.name.to_sym))
|
69
|
+
end
|
70
|
+
output << iterate_current_model(tag)
|
71
|
+
@_current_models.pop
|
72
|
+
when /^var/
|
73
|
+
unless @_current_var.nil?
|
74
|
+
output << @_current_var.send(tag.name.to_sym).to_s
|
75
|
+
else
|
76
|
+
output << "[UNDEFINED]"
|
77
|
+
end
|
78
|
+
else
|
79
|
+
raise "Invalid domain for tag"
|
80
|
+
end
|
81
|
+
output.join
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def iterate_current_model(tag)
|
86
|
+
return if @_current_models.empty?
|
87
|
+
output = []
|
88
|
+
@_current_models.last.each do |x|
|
89
|
+
@_current_var = x
|
90
|
+
output << parse(tag.thing) unless tag.thing.nil?
|
91
|
+
end
|
92
|
+
output.join
|
93
|
+
end
|
94
|
+
|
44
95
|
end
|
data/lib/txprails/template.rb
CHANGED
data/txprails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{txprails}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jose Miguel P\303\251rez Ruiz"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-10}
|
13
13
|
s.default_executable = %q{txprails}
|
14
14
|
s.description = %q{TXPRails is a template engine based on TextPattern for Rails.}
|
15
15
|
s.email = %q{josemiguel@perezruiz.com}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txprails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jose Miguel P\xC3\xA9rez Ruiz"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-10 00:00:00 +01:00
|
13
13
|
default_executable: txprails
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|