cells 4.0.0.beta5 → 4.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/lib/cell.rb +2 -2
- data/lib/cell/rails.rb +33 -0
- data/lib/cell/railtie.rb +21 -13
- data/lib/cell/templates.rb +8 -8
- data/lib/cell/version.rb +1 -1
- data/lib/cell/view_model.rb +30 -20
- data/lib/rails/generators/test_unit/cell/templates/unit_test.rb.erb +2 -2
- data/lib/rails/generators/test_unit/concept/templates/unit_test.rb.erb +3 -3
- data/test/cell_generator_test.rb +3 -0
- data/test/concept_generator_test.rb +7 -0
- data/test/concept_test.rb +1 -1
- data/test/layout_test.rb +1 -0
- data/test/partial_test.rb +1 -1
- data/test/prefixes_test.rb +2 -0
- data/test/rails4.2/Gemfile +3 -1
- data/test/rails4.2/app/assets/stylesheets/{application.css → application.css.erb} +2 -0
- data/test/rails4.2/app/cells/form_for/show.erb +7 -0
- data/test/rails4.2/app/cells/form_for_cell.rb +12 -0
- data/test/rails4.2/app/cells/formtastic/show.erb +12 -0
- data/test/rails4.2/app/cells/formtastic_cell.rb +13 -0
- data/test/rails4.2/app/cells/simple_form/show.erb +7 -0
- data/test/rails4.2/app/cells/simple_form_cell.rb +16 -0
- data/test/rails4.2/app/cells/song_cell.rb +3 -0
- data/test/rails4.2/app/controllers/songs_controller.rb +9 -0
- data/test/rails4.2/app/models/artist.rb +25 -0
- data/test/rails4.2/app/models/song.rb +25 -0
- data/test/rails4.2/app/views/songs/show.html.erb +1 -0
- data/test/rails4.2/config/routes.rb +2 -0
- data/test/rails4.2/engines/my_engine/my_engine.gemspec +1 -1
- data/test/rails4.2/test/integration/controller_test.rb +12 -0
- data/test/rails4.2/test/integration/form_for_test.rb +10 -0
- data/test/rails4.2/test/integration/formtastic_test.rb +11 -0
- data/test/rails4.2/test/integration/simple_form_test.rb +10 -0
- data/test/rails4.2/test/integration/url_helper_test.rb +25 -0
- data/test/render_test.rb +1 -0
- data/test/templates_test.rb +3 -2
- metadata +18 -4
- data/test/url_helper_test.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5c2400e9d14760d1546557317bc9e98f97bb3b7
|
4
|
+
data.tar.gz: 4d7de6cd09957c5c12b7bd8b7030ebb119d5c5d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cc1c784ecb8a5e5838650b1e31beac41a03c92d5df45205b7811342d6acaba8a5a4dabeabf8eb752bfa0480fa784bda88a914e08ee14de9ce0ba7d7d7d8d123
|
7
|
+
data.tar.gz: a9c00ab7bcb2ab01132202756e1227cf50a6a976e3de7d69e9d9c74960874b7e910403cec640b12b63665e641acb850e0be3382a2d641d986f11b7b47e2dbef3
|
data/CHANGES.md
CHANGED
@@ -18,6 +18,9 @@
|
|
18
18
|
|
19
19
|
* When using HAML, we do not use any of HAML's helper hacks to "fix" ActionView and XSS. While you might not note this, it removes tons of code from our stack.
|
20
20
|
|
21
|
+
## 4.0.0.beta6
|
22
|
+
|
23
|
+
* Removed `ViewModel::template_engine`. This is now done explicitly by including `Cell::Erb`, etc. and happens automatically in a Rails environment.
|
21
24
|
|
22
25
|
## 4.0.0.beta5
|
23
26
|
|
data/lib/cell.rb
CHANGED
@@ -12,8 +12,8 @@ module Cell
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class TemplateMissingError < RuntimeError
|
15
|
-
def initialize(prefixes, view
|
16
|
-
super("Template missing: view: `#{view.to_s}
|
15
|
+
def initialize(prefixes, view)
|
16
|
+
super("Template missing: view: `#{view.to_s}` prefixes: #{prefixes.inspect}")
|
17
17
|
end
|
18
18
|
end # Error
|
19
19
|
end
|
data/lib/cell/rails.rb
CHANGED
@@ -52,5 +52,38 @@ module Cell
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
# In Rails, there are about 10 different implementations of #url_for. Rails doesn't like the idea of objects, so they
|
57
|
+
# have helpers in modules. Those module are now included sequentially into other modules and/or classes. While they
|
58
|
+
# get included, they might or might not include methods, depending on the including module/class
|
59
|
+
# (example here: https://github.com/rails/rails/blob/cad20f720c4c6e04584253cd0a23f22b3d43ab0f/actionpack/lib/action_dispatch/routing/url_for.rb#L87).
|
60
|
+
#
|
61
|
+
# The outcome is that several module override #url_for, and if you're lucky, this works. If you're not, then #url_for breaks
|
62
|
+
# due to a raise in one of its basic implementations, introduced in 3.x, fixed in 4.0 and then re-introduced in 4.2
|
63
|
+
#
|
64
|
+
# This is extremely frustrating as no one in Rails core seems to tackle this problem and introduces a url object instead
|
65
|
+
# of this module madness. I have to constantly test and fix it in Cells. With the module below, I'll stop doing this.
|
66
|
+
#
|
67
|
+
# Either Rails works with Cells and we fix this in form of a URL object that gets passed into the cell (I'm happy with
|
68
|
+
# a global object here, too! Wow!) or URL helpers will stop working in Cells and a lot of people will be unhappy.
|
69
|
+
#
|
70
|
+
# Anyway, this is the reason we need this patch module. If you have trouble with URLs in Cells, then please ask Rails to
|
71
|
+
# fix their implementation. Thank you.
|
72
|
+
module HelpersAreShit
|
73
|
+
def url_for(options = nil) # from ActionDispatch:R:UrlFor.
|
74
|
+
case options
|
75
|
+
when nil
|
76
|
+
_routes.url_for(url_options.symbolize_keys)
|
77
|
+
when Hash
|
78
|
+
_routes.url_for(options.symbolize_keys.reverse_merge!(url_options))
|
79
|
+
when String
|
80
|
+
options
|
81
|
+
when Array
|
82
|
+
polymorphic_url(options, options.extract_options!)
|
83
|
+
else
|
84
|
+
polymorphic_url(options)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
55
88
|
end
|
56
89
|
end
|
data/lib/cell/railtie.rb
CHANGED
@@ -11,9 +11,9 @@ module Cell
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
initializer 'cells.template_engine' do |app|
|
15
|
-
|
16
|
-
end
|
14
|
+
# initializer 'cells.template_engine' do |app|
|
15
|
+
# ViewModel.template_engine = app.config.app_generators.rails.fetch(:template_engine, 'erb').to_s
|
16
|
+
# end
|
17
17
|
|
18
18
|
# ruthlessly stolen from the zurb-foundation gem.
|
19
19
|
initializer 'cells.update_asset_paths' do |app|
|
@@ -23,7 +23,7 @@ module Cell
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
initializer
|
26
|
+
initializer "cells.rails_extensions" do |app|
|
27
27
|
ActiveSupport.on_load(:action_controller) do
|
28
28
|
self.class_eval do
|
29
29
|
include ::Cell::RailsExtensions::ActionController
|
@@ -34,21 +34,29 @@ module Cell
|
|
34
34
|
self.class_eval do
|
35
35
|
include ::Cell::RailsExtensions::ActionView
|
36
36
|
end
|
37
|
+
end
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
initializer "cells.include_default_helpers" do
|
41
|
+
#include assert helpers (image_path, font_path, ect)
|
42
|
+
ViewModel.class_eval do
|
43
|
+
include ActionView::Helpers::UrlHelper
|
44
|
+
include ::Cell::RailsExtensions::HelpersAreShit
|
45
|
+
|
46
|
+
include ActionView::Helpers::AssetTagHelper
|
47
|
+
include ActionView::Helpers::FormTagHelper
|
42
48
|
end
|
43
49
|
|
44
50
|
# set VM#cache_store, etc.
|
45
51
|
ViewModel.send(:include, RailsExtensions::ViewModel)
|
52
|
+
end
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
# TODO: allow to turn off this.
|
55
|
+
initializer "cells.include_template_module", after: "cells.include_default_helpers" do
|
56
|
+
# yepp, this is happening. saves me a lot of coding in each extension.
|
57
|
+
ViewModel.send(:include, Cell::Erb) if Cell.const_defined?(:Erb)
|
58
|
+
ViewModel.send(:include, Cell::Haml) if Cell.const_defined?(:Haml)
|
59
|
+
ViewModel.send(:include, Cell::Slim) if Cell.const_defined?(:Slim)
|
52
60
|
end
|
53
61
|
|
54
62
|
initializer('cells.development') do |app|
|
data/lib/cell/templates.rb
CHANGED
@@ -2,10 +2,8 @@ module Cell
|
|
2
2
|
# Gets cached in production.
|
3
3
|
class Templates
|
4
4
|
# prefixes could be instance variable as they will never change.
|
5
|
-
def [](prefixes, view,
|
6
|
-
view
|
7
|
-
|
8
|
-
find_template(prefixes, view, engine)
|
5
|
+
def [](prefixes, view, options)
|
6
|
+
find_template(prefixes, view, options)
|
9
7
|
end
|
10
8
|
|
11
9
|
private
|
@@ -14,17 +12,19 @@ module Cell
|
|
14
12
|
@cache ||= Cache.new
|
15
13
|
end
|
16
14
|
|
17
|
-
def find_template(prefixes, view,
|
15
|
+
def find_template(prefixes, view, options) # options is not considered in cache key.
|
18
16
|
cache.fetch(prefixes, view) do |prefix|
|
19
17
|
# this block is run once per cell class per process, for each prefix/view tuple.
|
20
|
-
create(prefix, view)
|
18
|
+
create(prefix, view, options)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
def create(prefix, view)
|
22
|
+
def create(prefix, view, options)
|
25
23
|
# puts "...checking #{prefix}/#{view}"
|
26
24
|
return unless File.exists?("#{prefix}/#{view}") # DISCUSS: can we use Tilt.new here?
|
27
|
-
|
25
|
+
|
26
|
+
template_class = options.delete(:template_class)
|
27
|
+
template_class.new("#{prefix}/#{view}", options) # Tilt.new()
|
28
28
|
end
|
29
29
|
|
30
30
|
# {["comment/row/views", comment/views"][show.haml] => "Tpl:comment/view/show.haml"}
|
data/lib/cell/version.rb
CHANGED
data/lib/cell/view_model.rb
CHANGED
@@ -21,9 +21,6 @@ module Cell
|
|
21
21
|
inheritable_attr :view_paths
|
22
22
|
self.view_paths = ["app/cells"]
|
23
23
|
|
24
|
-
inheritable_attr :template_engine
|
25
|
-
self.template_engine = "erb"
|
26
|
-
|
27
24
|
class << self
|
28
25
|
def templates
|
29
26
|
@templates ||= Templates.new # note: this is shared in subclasses. do we really want this?
|
@@ -74,6 +71,7 @@ module Cell
|
|
74
71
|
|
75
72
|
include Helpers
|
76
73
|
|
74
|
+
# DISCUSS: introduce ::for which takes constant? rename ::build_cell to ::build?
|
77
75
|
|
78
76
|
def cell_for(name, *args)
|
79
77
|
class_from_cell_name(name).build_cell(*args)
|
@@ -115,16 +113,17 @@ module Cell
|
|
115
113
|
content.to_s
|
116
114
|
end
|
117
115
|
|
118
|
-
private
|
119
116
|
# render :show
|
120
117
|
def render(options={})
|
121
118
|
options = normalize_options(options, caller) # TODO: call render methods with call(:show), call(:comments) instead of directly #comments?
|
122
119
|
render_to_string(options)
|
123
120
|
end
|
124
121
|
|
122
|
+
private
|
125
123
|
def render_to_string(options)
|
126
|
-
template =
|
127
|
-
|
124
|
+
template = find_template(options) # TODO: cache template with path/lookup keys.
|
125
|
+
|
126
|
+
content = render_template(template, options)
|
128
127
|
|
129
128
|
# TODO: allow other (global) layout dirs.
|
130
129
|
with_layout(options, content)
|
@@ -133,6 +132,18 @@ module Cell
|
|
133
132
|
def render_state(*args)
|
134
133
|
send(*args)
|
135
134
|
end
|
135
|
+
|
136
|
+
def with_layout(options, content)
|
137
|
+
return content unless layout = options[:layout]
|
138
|
+
|
139
|
+
template = find_template(options.merge :view => layout) # we could also allow a different layout engine, etc.
|
140
|
+
|
141
|
+
render_template(template, options) { content }
|
142
|
+
end
|
143
|
+
|
144
|
+
def render_template(template, options, &block)
|
145
|
+
template.render(self, options[:locals], &block) # DISCUSS: hand locals to layout?
|
146
|
+
end
|
136
147
|
end
|
137
148
|
|
138
149
|
include Rendering
|
@@ -167,30 +178,30 @@ module Cell
|
|
167
178
|
end
|
168
179
|
end
|
169
180
|
def output_buffer # called from the precompiled template. FIXME: this is currently not used in Haml.
|
170
|
-
OutputBuffer.new # don't cache output_buffer, for every render call we get a fresh one.
|
181
|
+
OutputBuffer.new # don't cache output_buffer, for every #render call we get a fresh one.
|
171
182
|
end
|
172
|
-
attr_writer :output_buffer # FIXME: where is that used? definitely not in Erbse.
|
173
|
-
# TODO: remove output_buffer in favor or returning the string.
|
174
183
|
|
175
184
|
|
176
185
|
module TemplateFor
|
177
|
-
def
|
186
|
+
def find_template(options)
|
187
|
+
template_options = template_options_for(options) # imported by Erb, Haml, etc.
|
188
|
+
|
178
189
|
view = options[:view]
|
179
|
-
engine = options[:template_engine]
|
180
190
|
prefixes = options[:prefixes]
|
191
|
+
suffix = template_options[:suffix]
|
192
|
+
view = "#{view}.#{suffix}"
|
181
193
|
|
194
|
+
template_for(prefixes, view, template_options) or raise TemplateMissingError.new(prefixes, view)
|
195
|
+
end
|
196
|
+
|
197
|
+
def template_for(prefixes, view, options)
|
182
198
|
# we could also pass _prefixes when creating class.templates, because prefixes are never gonna change per instance. not too sure if i'm just assuming this or if people need that.
|
183
|
-
|
199
|
+
# Note: options here is the template-relevant options, only.
|
200
|
+
self.class.templates[prefixes, view, options]
|
184
201
|
end
|
185
202
|
end
|
186
203
|
include TemplateFor
|
187
204
|
|
188
|
-
def with_layout(options, content)
|
189
|
-
return content unless layout = options[:layout]
|
190
|
-
|
191
|
-
template = template_for(options.merge :view => layout) # we could also allow a different layout engine, etc.
|
192
|
-
template.render(self) { content }
|
193
|
-
end
|
194
205
|
|
195
206
|
def normalize_options(options, caller) # TODO: rename to #setup_options! to be inline with Trb.
|
196
207
|
options = if options.is_a?(Hash)
|
@@ -200,8 +211,7 @@ module Cell
|
|
200
211
|
{:view => options.to_s}
|
201
212
|
end
|
202
213
|
|
203
|
-
options[:
|
204
|
-
options[:prefixes] ||= _prefixes
|
214
|
+
options[:prefixes] ||= _prefixes
|
205
215
|
|
206
216
|
process_options!(options)
|
207
217
|
options
|
@@ -3,8 +3,8 @@ require 'test_helper'
|
|
3
3
|
class <%= class_name %>CellTest < Cell::TestCase
|
4
4
|
<% states.each do |state| -%>
|
5
5
|
test "<%= state %>" do
|
6
|
-
|
7
|
-
|
6
|
+
html = cell("<%= file_name %>").(:<%= state %>)
|
7
|
+
assert html.match /<p>/
|
8
8
|
end
|
9
9
|
|
10
10
|
<% end %>
|
@@ -3,9 +3,9 @@ require 'test_helper'
|
|
3
3
|
class <%= class_name %>ConceptTest < Cell::TestCase
|
4
4
|
<% states.each do |state| -%>
|
5
5
|
test "<%= state %>" do
|
6
|
-
|
7
|
-
|
6
|
+
html = concept("<%= file_name %>/cell").(:<%= state %>)
|
7
|
+
assert html.match /<p>/
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
<% end %>
|
11
11
|
end
|
data/test/cell_generator_test.rb
CHANGED
@@ -69,7 +69,10 @@ class CellGeneratorTest < Rails::Generators::TestCase
|
|
69
69
|
test 'create test_unit assets with -t test_unit' do
|
70
70
|
run_generator %w(Blog post latest -t test_unit)
|
71
71
|
|
72
|
+
# file is there.
|
72
73
|
assert_file 'test/cells/blog_cell_test.rb'
|
74
|
+
# file contains #cell(..) call.
|
75
|
+
assert_file 'test/cells/blog_cell_test.rb', /cell\("blog"\).\(:post\)/
|
73
76
|
end
|
74
77
|
|
75
78
|
test 'work with namespace and test_unit' do
|
@@ -15,6 +15,13 @@ class ConceptGeneratorTest < Rails::Generators::TestCase
|
|
15
15
|
assert_file 'app/concepts/song/views/show.erb', %r{app/concepts/song/views/show\.erb}
|
16
16
|
end
|
17
17
|
|
18
|
+
test "test unit test" do
|
19
|
+
run_generator %w(song -t test_unit)
|
20
|
+
|
21
|
+
# file contains #concept(..) call.
|
22
|
+
assert_file 'test/concepts/song/cell_test.rb', /concept\("song\/cell"\).\(:show\)/
|
23
|
+
end
|
24
|
+
|
18
25
|
test '[haml] standard assets, show view' do
|
19
26
|
run_generator %w(song -e haml)
|
20
27
|
|
data/test/concept_test.rb
CHANGED
data/test/layout_test.rb
CHANGED
data/test/partial_test.rb
CHANGED
data/test/prefixes_test.rb
CHANGED
@@ -84,6 +84,7 @@ end
|
|
84
84
|
class InheritViewsTest < MiniTest::Spec
|
85
85
|
class SlapperCell < Cell::ViewModel
|
86
86
|
self.view_paths = ['test/fixtures'] # todo: REMOVE!
|
87
|
+
include Cell::Erb
|
87
88
|
|
88
89
|
inherit_views ::BassistCell
|
89
90
|
|
@@ -106,6 +107,7 @@ class InheritViewsTest < MiniTest::Spec
|
|
106
107
|
# TapperCell
|
107
108
|
class TapperCell < Cell::ViewModel
|
108
109
|
self.view_paths = ['test/fixtures']
|
110
|
+
# include Cell::Erb
|
109
111
|
|
110
112
|
def play
|
111
113
|
render
|
data/test/rails4.2/Gemfile
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
<%= semantic_form_for Song.new do |f| %>
|
2
|
+
First
|
3
|
+
<%= f.input :id %>
|
4
|
+
<%= f.semantic_fields_for :artist do |a| %>
|
5
|
+
<%= a.input :id %>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<%= f.actions do %>
|
9
|
+
<%= f.submit 'Go!', as: :button, class: 'btn btn-primary' %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SimpleFormCell < Cell::ViewModel
|
2
|
+
include ActionView::RecordIdentifier
|
3
|
+
include ActionView::Helpers::FormHelper
|
4
|
+
include SimpleForm::ActionViewExtensions::FormHelper
|
5
|
+
|
6
|
+
# include ActiveSupport::Configurable
|
7
|
+
# include ActionController::RequestForgeryProtection # FIXME: this does NOT activate any protection.
|
8
|
+
|
9
|
+
def protect_against_forgery?
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
render
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Artist
|
2
|
+
require "active_model"
|
3
|
+
include ActiveModel::Conversion
|
4
|
+
include ActiveModel::Naming
|
5
|
+
|
6
|
+
def persisted?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def parents
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
"artist"
|
16
|
+
end
|
17
|
+
|
18
|
+
def id
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
# def artist
|
23
|
+
# Artist.new
|
24
|
+
# end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Song
|
2
|
+
require "active_model"
|
3
|
+
include ActiveModel::Conversion
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
|
6
|
+
def persisted?
|
7
|
+
true
|
8
|
+
end
|
9
|
+
|
10
|
+
def parents
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
"song"
|
16
|
+
end
|
17
|
+
|
18
|
+
def id
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
def artist
|
23
|
+
Artist.new
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= cell(:form_for) %>
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
18
18
|
|
19
19
|
s.add_dependency "rails", "~> 4.2.1"
|
20
|
-
s.add_dependency "cells", "4.0.0.
|
20
|
+
s.add_dependency "cells", ">= 4.0.0.beta5"
|
21
21
|
s.add_dependency "cells-erb"
|
22
22
|
|
23
23
|
s.add_development_dependency "sqlite3"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class FormForTestTest < MiniTest::Spec
|
4
|
+
include Cell::Testing
|
5
|
+
|
6
|
+
it do
|
7
|
+
cell("form_for").().gsub(/\s\s/, "").must_equal %{<form class=\"edit_song\" id=\"edit_song_1\" action=\"/songs/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /> First <input type=\"text\" value=\"1\" name=\"song[id]\" id=\"song_id\" /><input type=\"text\" name=\"song[artist][id]\" id=\"song_artist_id\" />
|
8
|
+
</form>}
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class FormForTestTest < MiniTest::Spec
|
4
|
+
include Cell::Testing
|
5
|
+
|
6
|
+
it do
|
7
|
+
cell("formtastic").().gsub(/\s\s/, "").must_equal %{<form novalidate=\"novalidate\" class=\"formtastic song\" id=\"edit_song_1\" action=\"/songs/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /> First <li class=\"string input required stringish\" id=\"song_id_input\"><label for=\"song_id\" class=\"label\">Id<abbr title=\"required\">*</abbr></label><input id=\"song_id\" type=\"text\" value=\"1\" name=\"song[id]\" /></li><li class=\"string input required stringish\" id=\"song_artist_id_input\"><label for=\"song_artist_id\" class=\"label\">Id<abbr title=\"required\">*</abbr></label><input id=\"song_artist_id\" type=\"text\" name=\"song[artist][id]\" /></li><fieldset class=\"actions\"><ol> <input type=\"submit\" name=\"commit\" value=\"Go!\" as=\"button\" class=\"btn btn-primary\" />
|
8
|
+
</ol></fieldset>
|
9
|
+
</form>}
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class SimpleFormTest < MiniTest::Spec
|
4
|
+
include Cell::Testing
|
5
|
+
|
6
|
+
it do
|
7
|
+
cell("simple_form").().gsub(/\s\s/, "").must_equal %{<form class=\"simple_form edit_song\" id=\"edit_song_1\" action=\"/songs/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"✓\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /> First <div class=\"input string required song_id\"><label class=\"string required\" for=\"song_id\"><abbr title=\"required\">*</abbr> Id</label><input class=\"string required\" required=\"required\" aria-required=\"true\" type=\"text\" value=\"1\" name=\"song[id]\" id=\"song_id\" /></div><div class=\"input string required song_artist_id\"><label class=\"string required\" for=\"song_artist_id\"><abbr title=\"required\">*</abbr> Id</label><input class=\"string required\" required=\"required\" aria-required=\"true\" type=\"text\" name=\"song[artist][id]\" id=\"song_artist_id\" /></div>
|
8
|
+
</form>}
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class MusiciansController < ApplicationController
|
4
|
+
end
|
5
|
+
|
6
|
+
class UrlHelperTest < MiniTest::Spec
|
7
|
+
include Cell::Testing
|
8
|
+
controller MusiciansController
|
9
|
+
|
10
|
+
class Cell < Cell::ViewModel
|
11
|
+
def show
|
12
|
+
url_for(model)
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_url_options
|
16
|
+
{host: "rails.sucks"}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let (:song_cell) { Cell.new(Song.new, controller: controller) }
|
21
|
+
|
22
|
+
# path helpers work in cell instance.
|
23
|
+
it { song_cell.songs_path.must_equal "/songs" }
|
24
|
+
it { song_cell.().must_equal "http://rails.sucks/songs/1" }
|
25
|
+
end
|
data/test/render_test.rb
CHANGED
data/test/templates_test.rb
CHANGED
@@ -5,10 +5,10 @@ class TemplatesTest < MiniTest::Spec
|
|
5
5
|
Templates = Cell::Templates
|
6
6
|
|
7
7
|
# existing.
|
8
|
-
it { Templates.new[['test/fixtures/bassist'], 'play',
|
8
|
+
it { Templates.new[['test/fixtures/bassist'], 'play.erb', {template_class: Tilt}].file.must_equal 'test/fixtures/bassist/play.erb' }
|
9
9
|
|
10
10
|
# not existing.
|
11
|
-
it { Templates.new[['test/fixtures/bassist'], 'not-here',
|
11
|
+
it { Templates.new[['test/fixtures/bassist'], 'not-here.erb', {}].must_equal nil }
|
12
12
|
|
13
13
|
|
14
14
|
# different caches for different classes
|
@@ -21,6 +21,7 @@ end
|
|
21
21
|
class TemplatesCachingTest < MiniTest::Spec
|
22
22
|
class SongCell < Cell::ViewModel
|
23
23
|
self.view_paths = ['test/fixtures']
|
24
|
+
# include Cell::Erb
|
24
25
|
|
25
26
|
def show
|
26
27
|
render
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cells
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uber
|
@@ -230,18 +230,28 @@ files:
|
|
230
230
|
- test/rails4.2/README.rdoc
|
231
231
|
- test/rails4.2/Rakefile
|
232
232
|
- test/rails4.2/app/assets/images/.keep
|
233
|
-
- test/rails4.2/app/assets/stylesheets/application.css
|
233
|
+
- test/rails4.2/app/assets/stylesheets/application.css.erb
|
234
|
+
- test/rails4.2/app/cells/form_for/show.erb
|
235
|
+
- test/rails4.2/app/cells/form_for_cell.rb
|
236
|
+
- test/rails4.2/app/cells/formtastic/show.erb
|
237
|
+
- test/rails4.2/app/cells/formtastic_cell.rb
|
238
|
+
- test/rails4.2/app/cells/simple_form/show.erb
|
239
|
+
- test/rails4.2/app/cells/simple_form_cell.rb
|
234
240
|
- test/rails4.2/app/cells/song/song.css
|
235
241
|
- test/rails4.2/app/cells/song_cell.rb
|
236
242
|
- test/rails4.2/app/controllers/application_controller.rb
|
237
243
|
- test/rails4.2/app/controllers/concerns/.keep
|
238
244
|
- test/rails4.2/app/controllers/index_controller.rb
|
245
|
+
- test/rails4.2/app/controllers/songs_controller.rb
|
239
246
|
- test/rails4.2/app/helpers/application_helper.rb
|
240
247
|
- test/rails4.2/app/mailers/.keep
|
241
248
|
- test/rails4.2/app/models/.keep
|
249
|
+
- test/rails4.2/app/models/artist.rb
|
242
250
|
- test/rails4.2/app/models/concerns/.keep
|
251
|
+
- test/rails4.2/app/models/song.rb
|
243
252
|
- test/rails4.2/app/views/index/index.html.erb
|
244
253
|
- test/rails4.2/app/views/layouts/application.html.erb
|
254
|
+
- test/rails4.2/app/views/songs/show.html.erb
|
245
255
|
- test/rails4.2/bin/bundle
|
246
256
|
- test/rails4.2/bin/rails
|
247
257
|
- test/rails4.2/bin/rake
|
@@ -299,6 +309,11 @@ files:
|
|
299
309
|
- test/rails4.2/public/favicon.ico
|
300
310
|
- test/rails4.2/public/robots.txt
|
301
311
|
- test/rails4.2/test/integration/asset_pipeline_test.rb
|
312
|
+
- test/rails4.2/test/integration/controller_test.rb
|
313
|
+
- test/rails4.2/test/integration/form_for_test.rb
|
314
|
+
- test/rails4.2/test/integration/formtastic_test.rb
|
315
|
+
- test/rails4.2/test/integration/simple_form_test.rb
|
316
|
+
- test/rails4.2/test/integration/url_helper_test.rb
|
302
317
|
- test/rails4.2/test/test_helper.rb
|
303
318
|
- test/rails4.2/vendor/assets/stylesheets/.keep
|
304
319
|
- test/rails_extensions_test.rb
|
@@ -307,7 +322,6 @@ files:
|
|
307
322
|
- test/test_case_test.rb
|
308
323
|
- test/test_helper.rb
|
309
324
|
- test/twin_test.rb
|
310
|
-
- test/url_helper_test.rb
|
311
325
|
homepage: https://github.com/apotonick/cells
|
312
326
|
licenses:
|
313
327
|
- MIT
|
data/test/url_helper_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MusiciansController < ApplicationController
|
4
|
-
end
|
5
|
-
|
6
|
-
class UrlHelperTest < MiniTest::Spec
|
7
|
-
controller MusiciansController
|
8
|
-
|
9
|
-
let (:song_cell) { SongCell.new(nil, controller: controller) }
|
10
|
-
|
11
|
-
class SongCell < Cell::ViewModel
|
12
|
-
end
|
13
|
-
|
14
|
-
# URL helpers work in cell instance.
|
15
|
-
it { song_cell.songs_path.must_equal "/songs" }
|
16
|
-
end
|