isotope 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +1 -0
- data/CHANGELOG.rdoc +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +11 -0
- data/LICENSE +18 -0
- data/Manifest +65 -0
- data/README.md +289 -0
- data/Rakefile +13 -0
- data/examples/rails3-example/Gemfile +34 -0
- data/examples/rails3-example/Gemfile.lock +77 -0
- data/examples/rails3-example/README +256 -0
- data/examples/rails3-example/Rakefile +7 -0
- data/examples/rails3-example/app/controllers/application_controller.rb +3 -0
- data/examples/rails3-example/app/controllers/articles_controller.rb +63 -0
- data/examples/rails3-example/app/helpers/application_helper.rb +2 -0
- data/examples/rails3-example/app/helpers/articles_helper.rb +2 -0
- data/examples/rails3-example/app/views/articles/article.html.ejs +11 -0
- data/examples/rails3-example/app/views/articles/show_client.html.erb +35 -0
- data/examples/rails3-example/app/views/articles/show_server_template_in_view.html.erb +4 -0
- data/examples/rails3-example/app/views/layouts/application.html.erb +13 -0
- data/examples/rails3-example/config.ru +4 -0
- data/examples/rails3-example/config/application.rb +42 -0
- data/examples/rails3-example/config/boot.rb +13 -0
- data/examples/rails3-example/config/database.yml +22 -0
- data/examples/rails3-example/config/environment.rb +5 -0
- data/examples/rails3-example/config/environments/development.rb +26 -0
- data/examples/rails3-example/config/environments/production.rb +49 -0
- data/examples/rails3-example/config/environments/test.rb +35 -0
- data/examples/rails3-example/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/rails3-example/config/initializers/inflections.rb +10 -0
- data/examples/rails3-example/config/initializers/mime_types.rb +5 -0
- data/examples/rails3-example/config/initializers/secret_token.rb +7 -0
- data/examples/rails3-example/config/initializers/session_store.rb +8 -0
- data/examples/rails3-example/config/locales/en.yml +5 -0
- data/examples/rails3-example/config/routes.rb +65 -0
- data/examples/rails3-example/db/development.sqlite3 +0 -0
- data/examples/rails3-example/db/seeds.rb +7 -0
- data/examples/rails3-example/doc/README_FOR_APP +2 -0
- data/examples/rails3-example/public/404.html +26 -0
- data/examples/rails3-example/public/422.html +26 -0
- data/examples/rails3-example/public/500.html +26 -0
- data/examples/rails3-example/public/favicon.ico +0 -0
- data/examples/rails3-example/public/images/rails.png +0 -0
- data/examples/rails3-example/public/index.html +239 -0
- data/examples/rails3-example/public/javascripts/application.js +2 -0
- data/examples/rails3-example/public/javascripts/controls.js +965 -0
- data/examples/rails3-example/public/javascripts/dragdrop.js +974 -0
- data/examples/rails3-example/public/javascripts/effects.js +1123 -0
- data/examples/rails3-example/public/javascripts/isotope.js +56 -0
- data/examples/rails3-example/public/javascripts/prototype.js +6001 -0
- data/examples/rails3-example/public/javascripts/rails.js +175 -0
- data/examples/rails3-example/public/robots.txt +5 -0
- data/examples/rails3-example/script/rails +6 -0
- data/examples/rails3-example/test/functional/articles_controller_test.rb +9 -0
- data/examples/rails3-example/test/performance/browsing_test.rb +9 -0
- data/examples/rails3-example/test/test_helper.rb +13 -0
- data/examples/rails3-example/test/unit/helpers/article_helper_test.rb +4 -0
- data/examples/rails3-example/test/unit/helpers/articles_helper_test.rb +4 -0
- data/examples/rails3-example/tmp/pids/server.pid +1 -0
- data/examples/sinatra-example/server.rb +4 -0
- data/isotope.gemspec +32 -0
- data/lib/isotope.js +53 -0
- data/lib/isotope.rb +75 -0
- data/lib/version.rb +9 -0
- data/test/article.ejs +11 -0
- data/test/isotope_spec.rb +103 -0
- metadata +163 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
(function() {
|
2
|
+
// Technique from Juriy Zaytsev
|
3
|
+
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
4
|
+
function isEventSupported(eventName) {
|
5
|
+
var el = document.createElement('div');
|
6
|
+
eventName = 'on' + eventName;
|
7
|
+
var isSupported = (eventName in el);
|
8
|
+
if (!isSupported) {
|
9
|
+
el.setAttribute(eventName, 'return;');
|
10
|
+
isSupported = typeof el[eventName] == 'function';
|
11
|
+
}
|
12
|
+
el = null;
|
13
|
+
return isSupported;
|
14
|
+
}
|
15
|
+
|
16
|
+
function isForm(element) {
|
17
|
+
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
|
18
|
+
}
|
19
|
+
|
20
|
+
function isInput(element) {
|
21
|
+
if (Object.isElement(element)) {
|
22
|
+
var name = element.nodeName.toUpperCase()
|
23
|
+
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
|
24
|
+
}
|
25
|
+
else return false
|
26
|
+
}
|
27
|
+
|
28
|
+
var submitBubbles = isEventSupported('submit'),
|
29
|
+
changeBubbles = isEventSupported('change')
|
30
|
+
|
31
|
+
if (!submitBubbles || !changeBubbles) {
|
32
|
+
// augment the Event.Handler class to observe custom events when needed
|
33
|
+
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
34
|
+
function(init, element, eventName, selector, callback) {
|
35
|
+
init(element, eventName, selector, callback)
|
36
|
+
// is the handler being attached to an element that doesn't support this event?
|
37
|
+
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
38
|
+
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
39
|
+
// "submit" => "emulated:submit"
|
40
|
+
this.eventName = 'emulated:' + this.eventName
|
41
|
+
}
|
42
|
+
}
|
43
|
+
)
|
44
|
+
}
|
45
|
+
|
46
|
+
if (!submitBubbles) {
|
47
|
+
// discover forms on the page by observing focus events which always bubble
|
48
|
+
document.on('focusin', 'form', function(focusEvent, form) {
|
49
|
+
// special handler for the real "submit" event (one-time operation)
|
50
|
+
if (!form.retrieve('emulated:submit')) {
|
51
|
+
form.on('submit', function(submitEvent) {
|
52
|
+
var emulated = form.fire('emulated:submit', submitEvent, true)
|
53
|
+
// if custom event received preventDefault, cancel the real one too
|
54
|
+
if (emulated.returnValue === false) submitEvent.preventDefault()
|
55
|
+
})
|
56
|
+
form.store('emulated:submit', true)
|
57
|
+
}
|
58
|
+
})
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!changeBubbles) {
|
62
|
+
// discover form inputs on the page
|
63
|
+
document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
|
64
|
+
// special handler for real "change" events
|
65
|
+
if (!input.retrieve('emulated:change')) {
|
66
|
+
input.on('change', function(changeEvent) {
|
67
|
+
input.fire('emulated:change', changeEvent, true)
|
68
|
+
})
|
69
|
+
input.store('emulated:change', true)
|
70
|
+
}
|
71
|
+
})
|
72
|
+
}
|
73
|
+
|
74
|
+
function handleRemote(element) {
|
75
|
+
var method, url, params;
|
76
|
+
|
77
|
+
var event = element.fire("ajax:before");
|
78
|
+
if (event.stopped) return false;
|
79
|
+
|
80
|
+
if (element.tagName.toLowerCase() === 'form') {
|
81
|
+
method = element.readAttribute('method') || 'post';
|
82
|
+
url = element.readAttribute('action');
|
83
|
+
params = element.serialize();
|
84
|
+
} else {
|
85
|
+
method = element.readAttribute('data-method') || 'get';
|
86
|
+
url = element.readAttribute('href');
|
87
|
+
params = {};
|
88
|
+
}
|
89
|
+
|
90
|
+
new Ajax.Request(url, {
|
91
|
+
method: method,
|
92
|
+
parameters: params,
|
93
|
+
evalScripts: true,
|
94
|
+
|
95
|
+
onComplete: function(request) { element.fire("ajax:complete", request); },
|
96
|
+
onSuccess: function(request) { element.fire("ajax:success", request); },
|
97
|
+
onFailure: function(request) { element.fire("ajax:failure", request); }
|
98
|
+
});
|
99
|
+
|
100
|
+
element.fire("ajax:after");
|
101
|
+
}
|
102
|
+
|
103
|
+
function handleMethod(element) {
|
104
|
+
var method = element.readAttribute('data-method'),
|
105
|
+
url = element.readAttribute('href'),
|
106
|
+
csrf_param = $$('meta[name=csrf-param]')[0],
|
107
|
+
csrf_token = $$('meta[name=csrf-token]')[0];
|
108
|
+
|
109
|
+
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
110
|
+
element.parentNode.insert(form);
|
111
|
+
|
112
|
+
if (method !== 'post') {
|
113
|
+
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
114
|
+
form.insert(field);
|
115
|
+
}
|
116
|
+
|
117
|
+
if (csrf_param) {
|
118
|
+
var param = csrf_param.readAttribute('content'),
|
119
|
+
token = csrf_token.readAttribute('content'),
|
120
|
+
field = new Element('input', { type: 'hidden', name: param, value: token });
|
121
|
+
form.insert(field);
|
122
|
+
}
|
123
|
+
|
124
|
+
form.submit();
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
document.on("click", "*[data-confirm]", function(event, element) {
|
129
|
+
var message = element.readAttribute('data-confirm');
|
130
|
+
if (!confirm(message)) event.stop();
|
131
|
+
});
|
132
|
+
|
133
|
+
document.on("click", "a[data-remote]", function(event, element) {
|
134
|
+
if (event.stopped) return;
|
135
|
+
handleRemote(element);
|
136
|
+
event.stop();
|
137
|
+
});
|
138
|
+
|
139
|
+
document.on("click", "a[data-method]", function(event, element) {
|
140
|
+
if (event.stopped) return;
|
141
|
+
handleMethod(element);
|
142
|
+
event.stop();
|
143
|
+
});
|
144
|
+
|
145
|
+
document.on("submit", function(event) {
|
146
|
+
var element = event.findElement(),
|
147
|
+
message = element.readAttribute('data-confirm');
|
148
|
+
if (message && !confirm(message)) {
|
149
|
+
event.stop();
|
150
|
+
return false;
|
151
|
+
}
|
152
|
+
|
153
|
+
var inputs = element.select("input[type=submit][data-disable-with]");
|
154
|
+
inputs.each(function(input) {
|
155
|
+
input.disabled = true;
|
156
|
+
input.writeAttribute('data-original-value', input.value);
|
157
|
+
input.value = input.readAttribute('data-disable-with');
|
158
|
+
});
|
159
|
+
|
160
|
+
var element = event.findElement("form[data-remote]");
|
161
|
+
if (element) {
|
162
|
+
handleRemote(element);
|
163
|
+
event.stop();
|
164
|
+
}
|
165
|
+
});
|
166
|
+
|
167
|
+
document.on("ajax:after", "form", function(event, element) {
|
168
|
+
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
169
|
+
inputs.each(function(input) {
|
170
|
+
input.value = input.readAttribute('data-original-value');
|
171
|
+
input.removeAttribute('data-original-value');
|
172
|
+
input.disabled = false;
|
173
|
+
});
|
174
|
+
});
|
175
|
+
})();
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
7
|
+
#
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
9
|
+
# -- they do not yet inherit this setting
|
10
|
+
fixtures :all
|
11
|
+
|
12
|
+
# Add more helper methods to be used by all tests here...
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
2689
|
data/isotope.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{isotope}
|
5
|
+
s.version = "1.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Elad Ossadon"]
|
9
|
+
s.cert_chain = ["/Users/Elad/.pem/gem-public_cert.pem"]
|
10
|
+
s.date = %q{2010-10-30}
|
11
|
+
s.description = %q{Isotope provides an easy way to use a signle EJS template on both server and client side}
|
12
|
+
s.email = %q{elad@ossadon.com}
|
13
|
+
s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE", "README.md", "lib/isotope.js", "lib/isotope.rb", "lib/version.rb"]
|
14
|
+
s.files = ["CHANGELOG.rdoc", "Gemfile", "Gemfile.lock", "LICENSE", "Manifest", "README.md", "Rakefile", "examples/rails3-example/Gemfile", "examples/rails3-example/Gemfile.lock", "examples/rails3-example/README", "examples/rails3-example/Rakefile", "examples/rails3-example/app/controllers/application_controller.rb", "examples/rails3-example/app/controllers/articles_controller.rb", "examples/rails3-example/app/helpers/application_helper.rb", "examples/rails3-example/app/helpers/articles_helper.rb", "examples/rails3-example/app/views/articles/article.html.ejs", "examples/rails3-example/app/views/articles/show_client.html.erb", "examples/rails3-example/app/views/articles/show_server_template_in_view.html.erb", "examples/rails3-example/app/views/layouts/application.html.erb", "examples/rails3-example/config.ru", "examples/rails3-example/config/application.rb", "examples/rails3-example/config/boot.rb", "examples/rails3-example/config/database.yml", "examples/rails3-example/config/environment.rb", "examples/rails3-example/config/environments/development.rb", "examples/rails3-example/config/environments/production.rb", "examples/rails3-example/config/environments/test.rb", "examples/rails3-example/config/initializers/backtrace_silencers.rb", "examples/rails3-example/config/initializers/inflections.rb", "examples/rails3-example/config/initializers/mime_types.rb", "examples/rails3-example/config/initializers/secret_token.rb", "examples/rails3-example/config/initializers/session_store.rb", "examples/rails3-example/config/locales/en.yml", "examples/rails3-example/config/routes.rb", "examples/rails3-example/db/development.sqlite3", "examples/rails3-example/db/seeds.rb", "examples/rails3-example/doc/README_FOR_APP", "examples/rails3-example/public/404.html", "examples/rails3-example/public/422.html", "examples/rails3-example/public/500.html", "examples/rails3-example/public/favicon.ico", "examples/rails3-example/public/images/rails.png", "examples/rails3-example/public/index.html", "examples/rails3-example/public/javascripts/application.js", "examples/rails3-example/public/javascripts/controls.js", "examples/rails3-example/public/javascripts/dragdrop.js", "examples/rails3-example/public/javascripts/effects.js", "examples/rails3-example/public/javascripts/isotope.js", "examples/rails3-example/public/javascripts/prototype.js", "examples/rails3-example/public/javascripts/rails.js", "examples/rails3-example/public/robots.txt", "examples/rails3-example/script/rails", "examples/rails3-example/test/functional/articles_controller_test.rb", "examples/rails3-example/test/performance/browsing_test.rb", "examples/rails3-example/test/test_helper.rb", "examples/rails3-example/test/unit/helpers/article_helper_test.rb", "examples/rails3-example/test/unit/helpers/articles_helper_test.rb", "examples/rails3-example/tmp/pids/server.pid", "examples/sinatra-example/server.rb", "isotope.gemspec", "lib/isotope.js", "lib/isotope.rb", "lib/version.rb", "test/article.ejs", "test/isotope_spec.rb"]
|
15
|
+
s.homepage = %q{http://github.com/elado/isotope}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Isotope", "--main", "README.md"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{isotope}
|
19
|
+
s.rubygems_version = %q{1.3.7}
|
20
|
+
s.signing_key = %q{/Users/Elad/.pem/gem-private_key.pem}
|
21
|
+
s.summary = %q{Ruby Hybrid (Server and Client sides) templates}
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
data/lib/isotope.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
// Simple JavaScript Templating
|
2
|
+
// John Resig - http://ejohn.org/ - MIT Licensed
|
3
|
+
|
4
|
+
(function(){
|
5
|
+
var cache = {};
|
6
|
+
|
7
|
+
this.Isotope = function tmpl(str, data, options){
|
8
|
+
// Figure out if we're getting a template, or if we need to
|
9
|
+
// load the template - and be sure to cache the result.
|
10
|
+
var fn = cache[str] = cache[str] ||
|
11
|
+
|
12
|
+
// Generate a reusable function that will serve as a template
|
13
|
+
// generator (and which will be cached).
|
14
|
+
new Function("obj",
|
15
|
+
"var p=[],print=function(){p.push.apply(p,arguments);};" +
|
16
|
+
|
17
|
+
// Introduce the data as local variables using with(){}
|
18
|
+
"with(obj){p.push('" +
|
19
|
+
|
20
|
+
// Convert the template into pure JavaScript
|
21
|
+
str
|
22
|
+
.replace(/[\r\t\n]/g, " ")
|
23
|
+
.split("<%").join("\t")
|
24
|
+
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
|
25
|
+
.replace(/\t=(.*?)%>/g, "',$1,'")
|
26
|
+
.split("\t").join("');")
|
27
|
+
.split("%>").join("p.push('")
|
28
|
+
.split("\r").join("\\'")
|
29
|
+
+ "');}return p.join('');");
|
30
|
+
|
31
|
+
// Provide some basic currying to the user
|
32
|
+
|
33
|
+
if (data) {
|
34
|
+
options=options || {};
|
35
|
+
|
36
|
+
if (data instanceof Array) {
|
37
|
+
var s=[];
|
38
|
+
for (var i=0;i<data.length;i++) {
|
39
|
+
var itemObject={};
|
40
|
+
itemObject[options.localName || "item"]=data[i];
|
41
|
+
|
42
|
+
s.push(fn(itemObject));
|
43
|
+
}
|
44
|
+
return s.join(options.delimeter || "");
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
return fn( data );
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
return fn;
|
52
|
+
};
|
53
|
+
})();
|
data/lib/isotope.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'johnson'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Isotope
|
6
|
+
@@_template_cache = {}
|
7
|
+
|
8
|
+
@@cache_templates = true
|
9
|
+
|
10
|
+
def cache_templates
|
11
|
+
@@cache_templates
|
12
|
+
end
|
13
|
+
|
14
|
+
def cache_templates=(value)
|
15
|
+
if !value
|
16
|
+
@@_template_cache.clear
|
17
|
+
end
|
18
|
+
|
19
|
+
@@cache_templates = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.render_partial(view_file, options = {})
|
23
|
+
if options[:collection] && options[:collection].kind_of?(Enumerable)
|
24
|
+
return render_partial_collection(view_file, options)
|
25
|
+
end
|
26
|
+
|
27
|
+
isotope_file_path = File.join(File.dirname(__FILE__), "isotope.js")
|
28
|
+
|
29
|
+
view_file_content = template_file_content(view_file)
|
30
|
+
|
31
|
+
script = "
|
32
|
+
Johnson.runtime.load('#{isotope_file_path}');
|
33
|
+
Isotope(#{view_file_content.to_json}, #{options[:locals].to_json});
|
34
|
+
"
|
35
|
+
|
36
|
+
# puts script
|
37
|
+
|
38
|
+
output = Johnson.evaluate(script)
|
39
|
+
|
40
|
+
output
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.render_partial_collection(view_file, options = {})
|
44
|
+
s = []
|
45
|
+
|
46
|
+
options.delete(:collection).each { |item|
|
47
|
+
item_options = options.dup
|
48
|
+
item_options[:locals] ||= {}
|
49
|
+
item_options[:locals][options[:local_name] || :item] = item
|
50
|
+
|
51
|
+
s << render_partial(view_file, item_options)
|
52
|
+
}
|
53
|
+
|
54
|
+
s = s.join(options[:delimeter] || "")
|
55
|
+
|
56
|
+
s
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.render_template(view_file, options = {})
|
60
|
+
options[:id] = "template" unless options[:id]
|
61
|
+
|
62
|
+
view_file_content = template_file_content(view_file)
|
63
|
+
template_string = "<script type=\"text/x-isotope\" id=\"#{options[:id]}\">#{view_file_content}</script>"
|
64
|
+
|
65
|
+
template_string
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.template_file_content(view_file)
|
69
|
+
if @@cache_templates
|
70
|
+
@@_template_cache[view_file] ||= IO.read(view_file)
|
71
|
+
else
|
72
|
+
IO.read(view_file)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/version.rb
ADDED
data/test/article.ejs
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/isotope')
|
3
|
+
|
4
|
+
describe Isotope do
|
5
|
+
before :all do
|
6
|
+
@articles = dummy_articles
|
7
|
+
@template_file = File.join(File.dirname(__FILE__), "article.ejs")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should output a js template" do
|
11
|
+
s = Isotope.render_template(@template_file, :id => "hello")
|
12
|
+
|
13
|
+
s.should_not be_nil
|
14
|
+
|
15
|
+
s.strip.gsub(/\t| {2,}/, "").should eql('
|
16
|
+
<script type="text/x-isotope" id="hello"><h2><%=item.title%></h2>
|
17
|
+
|
18
|
+
<div class="content">
|
19
|
+
<%=item.content%>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<ul class="tags">
|
23
|
+
<%item.tags.forEach(function (tag) {%>
|
24
|
+
<li><%=tag.name%></li>
|
25
|
+
<%});%>
|
26
|
+
</ul></script>'.strip.gsub(/\t| {2,}/, "")
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should render articles" do
|
31
|
+
evaluated_content = Isotope.render_partial(@template_file, :locals => { :item => @articles[0] })
|
32
|
+
|
33
|
+
expected_content = '
|
34
|
+
<h2>Hello!</h2>
|
35
|
+
<div class="content">
|
36
|
+
World!
|
37
|
+
</div>
|
38
|
+
<ul class="tags">
|
39
|
+
<li>tag 1</li>
|
40
|
+
<li>tag 2</li>
|
41
|
+
<li>tag 3</li>
|
42
|
+
<li>tag 4</li>
|
43
|
+
</ul>
|
44
|
+
'
|
45
|
+
# white spaces are not important to equalize
|
46
|
+
evaluated_content.gsub(/\s/, "").should eql(expected_content.gsub(/\s/, ""))
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should render an array of articles" do
|
50
|
+
evaluated_content = Isotope.render_partial(@template_file, :collection => @articles, :delimeter => "<hr/>")
|
51
|
+
|
52
|
+
expected_content = '
|
53
|
+
<h2>Hello!</h2>
|
54
|
+
<div class="content">
|
55
|
+
World!
|
56
|
+
</div>
|
57
|
+
<ul class="tags">
|
58
|
+
<li>tag 1</li>
|
59
|
+
<li>tag 2</li>
|
60
|
+
<li>tag 3</li>
|
61
|
+
<li>tag 4</li>
|
62
|
+
</ul>
|
63
|
+
<hr/>
|
64
|
+
<h2>Hello 2!</h2>
|
65
|
+
<div class="content">
|
66
|
+
World 2!
|
67
|
+
</div>
|
68
|
+
<ul class="tags">
|
69
|
+
<li>tag 5</li>
|
70
|
+
<li>tag 6</li>
|
71
|
+
<li>tag 7</li>
|
72
|
+
<li>tag 8</li>
|
73
|
+
</ul>
|
74
|
+
'
|
75
|
+
|
76
|
+
evaluated_content.gsub(/\s/, "").should eql(expected_content.gsub(/\s/, ""))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def dummy_articles
|
81
|
+
[
|
82
|
+
{
|
83
|
+
:title => "Hello!",
|
84
|
+
:content => "World!",
|
85
|
+
:tags => [
|
86
|
+
{:name => "tag 1"},
|
87
|
+
{:name => "tag 2"},
|
88
|
+
{:name => "tag 3"},
|
89
|
+
{:name => "tag 4"}
|
90
|
+
]
|
91
|
+
},
|
92
|
+
{
|
93
|
+
:title => "Hello 2!",
|
94
|
+
:content => "World 2!",
|
95
|
+
:tags => [
|
96
|
+
{:name => "tag 5"},
|
97
|
+
{:name => "tag 6"},
|
98
|
+
{:name => "tag 7"},
|
99
|
+
{:name => "tag 8"}
|
100
|
+
]
|
101
|
+
}
|
102
|
+
]
|
103
|
+
end
|