ice 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +29 -17
- data/VERSION +1 -1
- data/ice.gemspec +1 -1
- data/lib/ice/base_cube.rb +1 -0
- data/lib/ice/cubeable.rb +1 -0
- metadata +2 -2
data/README.markdown
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# Ice Ice Baby!
|
2
2
|
|
3
|
-
|
3
|
+
The Ice project allows user-created templates to be written in the javascript programming language. They are then interpreted in a sandboxed environment. Ice is similar to Liquid in terms of safety, but uses javascript to leverage the powers of a language most developers are familiar with.
|
4
4
|
|
5
|
-
|
5
|
+
Ice runs the templates through an erb-ish parser and then uses the [therubyracer](http://github.com/cowboyd/therubyracer) to interpet the javascript using Google's V8 javascript engine. Your users can then write Ice templates like:
|
6
6
|
|
7
7
|
<table>
|
8
8
|
<tr><th>Name</th><th>Email</th></tr>
|
@@ -13,27 +13,40 @@ It runs the templates through an erb-ish parser and then uses the [therubyracer]
|
|
13
13
|
<% } %>
|
14
14
|
</table>
|
15
15
|
|
16
|
-
|
16
|
+
These templates can be run from the appropriate views directory, provided they have a .ice extension. Also, the templates may be compiled on demand with the method:
|
17
|
+
|
18
|
+
Ice.convert_template(template_text, vars = {})
|
19
|
+
|
20
|
+
## Why another templating engine when there is Liquid?
|
17
21
|
|
18
22
|
Liquid is excellent but has several disadvantages
|
19
23
|
|
20
24
|
* Hard to extend without knowing Liquid internals
|
21
|
-
* Introduces yet-another-language, whereas many designers are already familiar with javascript
|
22
|
-
* Doesn't allow template
|
23
|
-
* Doesn't have a rich set of support libraries like javascript brings to the table
|
25
|
+
* Introduces yet-another-language, whereas many designers/developers are already familiar with javascript
|
26
|
+
* Doesn't allow template creators to use a rich object model and easily create their own functions
|
27
|
+
* Doesn't have a rich set of support libraries like what javascript brings to the table
|
28
|
+
|
29
|
+
Note that we're still big fans of Liquid. In fact, we call this project "Ice" as a tribute (extending the metaphor, we use "Cubes" where they have "Drops").
|
24
30
|
|
25
|
-
|
31
|
+
## Installation
|
26
32
|
|
27
|
-
|
33
|
+
For Rails:
|
28
34
|
|
35
|
+
config.gem 'ice'
|
36
|
+
|
37
|
+
Otherwise:
|
38
|
+
|
39
|
+
gem install ice
|
29
40
|
|
30
41
|
## to_ice
|
31
42
|
|
32
|
-
Every object is revealed to the templates via its to_ice method. This helps filter the objects that are passed into the javascript, so people editing the
|
43
|
+
Every object is revealed to the templates via its to_ice method. This helps filter the objects that are passed into the javascript, so people editing the template only have access to a sanitized version of the data that you want them to format.
|
33
44
|
|
34
45
|
Instances of some classes like String and Numeric just return themselves as the result of to_ice. Hashes and Arrays run to_ice recursively on their members.
|
35
46
|
|
36
|
-
|
47
|
+
If you want an object to map to a different representation, simply define a to_ice object that returns whatever object you want to represent it within the javascript template. These objects are referred to as "Cubes", and are equivalent to "Drops" for those used to the Liquid template.
|
48
|
+
|
49
|
+
## ActiveRecord and to_ice
|
37
50
|
|
38
51
|
To make life easy, since most complex objects passed to the templates will be subclasses of ActiveRecord::Base, the default to_ice behaviour of ActiveRecord is to pass itself in to a class with the same name, but followed by the word "Cube".
|
39
52
|
|
@@ -51,16 +64,16 @@ In order for everything to work easily, you can have your cubes inherit from our
|
|
51
64
|
|
52
65
|
would provide a cube with access to the title, author_id and genre properties of the underlying ActiveRecord.
|
53
66
|
|
54
|
-
These cubes also have belongs_to and has_many associations, so you can write things like:
|
67
|
+
These cubes also have simple belongs_to and has_many associations, so you can write things like:
|
55
68
|
|
56
69
|
class ArticleCube < Ice::BaseCube
|
57
70
|
has_many :comments, :tags
|
58
71
|
belongs_to :author, :section
|
59
72
|
end
|
60
73
|
|
61
|
-
This
|
74
|
+
This generates association helper functions such as comment_ids, num_comments, has_comments, comments, author_id, and author.
|
62
75
|
|
63
|
-
Note that all revealed functions
|
76
|
+
Note that the results of all associations and revealed functions are also sanitized via to_ice.
|
64
77
|
|
65
78
|
## Note on Patches/Pull Requests
|
66
79
|
|
@@ -72,11 +85,10 @@ Note that all revealed functions and associations are also sanitized via to_ice.
|
|
72
85
|
|
73
86
|
## Todo
|
74
87
|
|
75
|
-
*
|
76
|
-
* Add in form builders from clots project
|
88
|
+
* Add in form builders (from clots project)
|
77
89
|
* Break form builders and helpers out into separate javascript project that can be included in other frameworks like CakePHP
|
78
90
|
* Allow mappings for other ORMs than ActiveRecord
|
79
|
-
* Haml support
|
91
|
+
* Haml support (really just deciding what extension those files would use :))
|
80
92
|
|
81
93
|
## Copyright
|
82
94
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/ice.gemspec
CHANGED
data/lib/ice/base_cube.rb
CHANGED
data/lib/ice/cubeable.rb
CHANGED