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 CHANGED
@@ -1,8 +1,8 @@
1
- # ice
1
+ # Ice Ice Baby!
2
2
 
3
- This project allows user-submitted templates to be written in the javascript programming language. It is similar to Liquid in terms of safety, but uses javascript to leverage the powers of a language most developers are familiar with.
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
- It 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:
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
- ## Why another templating engine when there is Liquid
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 editors to use a rich object model and create their own functions
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
- Note that we're still big fans of Liquid. In fact, we call this project "ice" as a tribute (keeping the metaphor alive, we use "Cubes" where they have "Drops").
31
+ ## Installation
26
32
 
27
- Laminate uses the Lua language, which is a slight improvement, but still is unfamiliar to most developers.
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 page only have access to a sanitized version of your data.
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
- ## ActiveRecord modifications
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 brings in association helper functions such as comment_ids, num_comments, has_comments, comments, author_id, and author.
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 and associations are also sanitized via to_ice.
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
- * Allow .ice view files
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.0
1
+ 0.2.1
data/ice.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ice}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nate Kidwell"]
data/lib/ice/base_cube.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module Ice
2
2
  class BaseCube
3
+ extend Ice::CubeAssociation
3
4
 
4
5
  def self.revealing(* attributes)
5
6
  attributes.each do |attr|
data/lib/ice/cubeable.rb CHANGED
@@ -3,6 +3,7 @@ module Ice
3
3
  def get_cube_class(class_obj)
4
4
  begin
5
5
  cube_string = class_obj.to_s + "Cube"
6
+ puts "getting string #{cube_string}"
6
7
  cube_string.constantize
7
8
  rescue
8
9
  get_cube_class class_obj.superclass
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nate Kidwell