presenting 1.0.0 → 2.0.0
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/app/controllers/presentation/assets_controller.rb +1 -1
- data/app/views/presentations/_details.erb +1 -1
- data/app/views/presentations/_field_search.erb +1 -1
- data/app/views/presentations/_form.erb +1 -1
- data/app/views/presentations/_grid.erb +1 -1
- data/app/views/presentations/_search.erb +1 -1
- data/config/routes.rb +7 -2
- data/lib/presentation/base.rb +10 -27
- data/lib/presentation/details.rb +2 -0
- data/lib/presentation/field_search.rb +2 -0
- data/lib/presentation/grid.rb +1 -1
- data/lib/presenting/engine.rb +7 -0
- data/lib/presenting/form_helpers.rb +1 -1
- data/lib/presenting/helpers.rb +7 -3
- data/lib/presenting/view.rb +3 -3
- data/lib/presenting.rb +38 -5
- data/test/assets_test.rb +5 -7
- data/test/details_test.rb +1 -1
- data/test/field_search_test.rb +1 -1
- data/test/form_test.rb +316 -287
- data/test/grid_test.rb +28 -8
- data/test/helpers_test.rb +2 -2
- data/test/presenting_test.rb +1 -1
- data/test/r3/Gemfile +7 -0
- data/test/r3/Gemfile.lock +82 -0
- data/test/r3/config/application.rb +12 -0
- data/test/r3/config/boot.rb +6 -0
- data/test/{rails → r3}/config/database.yml +6 -1
- data/test/r3/config/environment.rb +5 -0
- data/test/r3/config/environments/test.rb +35 -0
- data/test/r3/config.ru +4 -0
- data/test/r3/db/test.sqlite3 +0 -0
- data/test/r3/log/test.log +2354 -0
- data/test/r3/public/javascripts/presenting/grid.js +0 -0
- data/test/r3/public/javascripts/presenting/search.js +13 -0
- data/test/r3/public/stylesheets/presenting/details-color.css +7 -0
- data/test/r3/public/stylesheets/presenting/details.css +10 -0
- data/test/r3/public/stylesheets/presenting/form.css +1 -0
- data/test/r3/public/stylesheets/presenting/grid-color.css +71 -0
- data/test/r3/public/stylesheets/presenting/grid.css +64 -0
- data/test/r3/public/stylesheets/presenting/search-color.css +16 -0
- data/test/r3/public/stylesheets/presenting/search.css +45 -0
- data/test/search_conditions_test.rb +2 -2
- data/test/search_test.rb +1 -1
- data/test/test_helper.rb +8 -39
- metadata +45 -79
- data/rails/init.rb +0 -12
- data/test/rails/app/controllers/application_controller.rb +0 -15
- data/test/rails/app/controllers/users_controller.rb +0 -36
- data/test/rails/app/helpers/application_helper.rb +0 -3
- data/test/rails/app/helpers/users_helper.rb +0 -2
- data/test/rails/app/models/user.rb +0 -2
- data/test/rails/app/views/layouts/application.html.erb +0 -15
- data/test/rails/app/views/users/index.html.erb +0 -10
- data/test/rails/app/views/users/new.html.erb +0 -2
- data/test/rails/app/views/users/show.html.erb +0 -1
- data/test/rails/config/boot.rb +0 -109
- data/test/rails/config/environment.rb +0 -13
- data/test/rails/config/environments/development.rb +0 -17
- data/test/rails/config/environments/production.rb +0 -24
- data/test/rails/config/environments/test.rb +0 -22
- data/test/rails/config/locales/en.yml +0 -5
- data/test/rails/config/routes.rb +0 -5
- data/test/rails/db/development.sqlite3 +0 -0
- data/test/rails/db/migrate/20090213085444_create_users.rb +0 -13
- data/test/rails/db/migrate/20090213085607_populate_users.rb +0 -13
- data/test/rails/db/schema.rb +0 -23
- data/test/rails/db/test.sqlite3 +0 -0
- data/test/rails/log/development.log +0 -858
- data/test/rails/public/404.html +0 -30
- data/test/rails/public/422.html +0 -30
- data/test/rails/public/500.html +0 -33
- data/test/rails/public/javascripts/application.js +0 -2
- data/test/rails/public/javascripts/jquery.livequery.min.js +0 -11
- data/test/rails/public/javascripts/prototype.js +0 -4320
- data/test/rails/script/console +0 -3
- data/test/rails/script/dbconsole +0 -3
- data/test/rails/script/destroy +0 -3
- data/test/rails/script/generate +0 -3
- data/test/rails/script/plugin +0 -3
- data/test/rails/script/runner +0 -3
- data/test/rails/script/server +0 -3
- /data/app/assets/{javascript → javascripts}/grid.js +0 -0
- /data/app/assets/{javascript → javascripts}/search.js +0 -0
@@ -26,7 +26,7 @@ class Presentation::AssetsController < ActionController::Base
|
|
26
26
|
# - - required fields
|
27
27
|
# TODO: tests for ujs
|
28
28
|
def javascript
|
29
|
-
dir = asset_path(:
|
29
|
+
dir = asset_path(:javascripts)
|
30
30
|
script = params[:id].split(',').collect{ |id| File.read("#{dir}/#{id}.js") }.join("\n")
|
31
31
|
|
32
32
|
respond_to do |type|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
<dl>
|
6
6
|
<% @details.fields.each do |field| %>
|
7
7
|
<dt><%= field.name %></dt>
|
8
|
-
<dd><%= present(field.value_from(@details.presentable), :
|
8
|
+
<dd><%= present(field.value_from(@details.presentable), :raw => !field.sanitize?) %></dd>
|
9
9
|
<% end %>
|
10
10
|
</dl>
|
11
11
|
</div>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="presentation-search">
|
2
|
-
|
2
|
+
<%= form_tag @search.url, :method => :get, :class => ("compact" if @search.compact) do %>
|
3
3
|
<% @search.fields.each do |field| %>
|
4
4
|
<fieldset>
|
5
5
|
<label><%= field.name %></label>
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
<%= form_for @form.presentable, :url => @form.url, :method => @form.method, :html => @form.html do |f| %>
|
2
2
|
<% @form.groups.each do |group| %>
|
3
3
|
<fieldset>
|
4
4
|
<% unless group.name.blank? %>
|
@@ -41,7 +41,7 @@
|
|
41
41
|
<tr class="<%= cycle('odd', 'even') %>">
|
42
42
|
<% @grid.fields.each do |field| %>
|
43
43
|
<td class="<%= [field.id, ('sorted' if field.is_sorted?(request))].compact.join(' ') %>">
|
44
|
-
<%= present(field.value_from(record), :
|
44
|
+
<%= present(field.value_from(record), :raw => !field.sanitize?) %>
|
45
45
|
</td>
|
46
46
|
<% end %>
|
47
47
|
<% unless @grid.record_links.empty? %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<div class="presentation-search">
|
2
|
-
|
2
|
+
<%= form_tag @search.url, :method => :get do %>
|
3
3
|
<%= text_field_tag 'search', params[:search] %>
|
4
4
|
<input type="submit" value="Search" class="submit" />
|
5
5
|
<%= link_to 'reset', @search.url %>
|
data/config/routes.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
namespace :presentation do
|
3
|
+
controller 'assets' do
|
4
|
+
match 'stylesheets/:id.:format', :as => 'stylesheet', :action => 'stylesheet', :constraints => {:format => 'css'}
|
5
|
+
match 'javascript/:id.:format', :as => 'javascript', :action => 'javascript', :constraints => {:format => 'js'}
|
6
|
+
end
|
7
|
+
end
|
3
8
|
end
|
data/lib/presentation/base.rb
CHANGED
@@ -1,48 +1,31 @@
|
|
1
1
|
module Presentation
|
2
2
|
class Base
|
3
3
|
include Presenting::Configurable
|
4
|
-
|
4
|
+
|
5
5
|
def render
|
6
6
|
view.render :partial => "presentations/#{self.class.to_s.split('::').last.underscore}"
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
attr_accessor :presentable
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
attr_accessor :controller # not strictly for compat, but it makes the compat easy
|
16
|
-
|
17
|
-
def request
|
18
|
-
controller.request
|
19
|
-
end
|
20
|
-
|
21
|
-
def url_for(*args)
|
22
|
-
controller.url_for(*args)
|
23
|
-
end
|
24
|
-
|
25
|
-
def params
|
26
|
-
request.parameters
|
27
|
-
end
|
28
|
-
|
29
|
-
## end ActionView compat
|
30
|
-
|
10
|
+
|
11
|
+
attr_accessor :controller
|
12
|
+
delegate :request, :form_authenticity_token, :url_for, :params, :to => 'controller'
|
13
|
+
|
31
14
|
protected
|
32
|
-
|
15
|
+
|
33
16
|
# what the presentation is called in its templates
|
34
17
|
def iname
|
35
18
|
:presentation
|
36
19
|
end
|
37
|
-
|
20
|
+
|
38
21
|
# a reference to the view
|
39
22
|
def view #:nodoc:
|
40
23
|
@view ||= Presenting::View.new(ActionController::Base.view_paths, assigns_for_view, self)
|
41
24
|
end
|
42
|
-
|
25
|
+
|
43
26
|
def assigns_for_view
|
44
27
|
{iname => self, :_request => request}
|
45
28
|
end
|
46
|
-
|
29
|
+
|
47
30
|
end
|
48
31
|
end
|
data/lib/presentation/details.rb
CHANGED
data/lib/presentation/grid.rb
CHANGED
@@ -154,7 +154,7 @@ module Presentation
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def paginate?
|
157
|
-
defined? WillPaginate and presentable.is_a?
|
157
|
+
defined? WillPaginate and (presentable.is_a? WillPaginate::Collection or presentable.respond_to?(:total_entries))
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
data/lib/presenting/helpers.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Presenting
|
2
2
|
module Helpers
|
3
3
|
def presentation_stylesheets(*args)
|
4
|
-
|
4
|
+
warn "[DEPRECATION] presentation_stylesheets is deprecated. Please use the stylesheets" <<
|
5
|
+
"that are copied to public/stylesheets/presenting/* on boot."
|
6
|
+
stylesheet_link_tag presentation_stylesheet_path(args.sort.join(','), :format => 'css')
|
5
7
|
end
|
6
8
|
|
7
9
|
def presentation_javascript(*args)
|
8
|
-
|
10
|
+
warn "[DEPRECATION] presentation_javascript is deprecated. Please use the javascripts" <<
|
11
|
+
"that are copied to public/javascripts/presenting/* on boot."
|
12
|
+
javascript_include_tag presentation_javascript_path(args.sort.join(','), :format => 'js')
|
9
13
|
end
|
10
14
|
|
11
15
|
def present(*args, &block)
|
@@ -103,7 +107,7 @@ module Presenting
|
|
103
107
|
l(object, :format => :default)
|
104
108
|
|
105
109
|
else
|
106
|
-
options[:
|
110
|
+
options[:raw] ? object.to_s.html_safe : object.to_s
|
107
111
|
end
|
108
112
|
end
|
109
113
|
end
|
data/lib/presenting/view.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Presenting::View < ActionView::Base
|
2
|
-
delegate :protect_against_forgery?, :form_authenticity_token, :to => :controller
|
3
|
-
end
|
1
|
+
class Presenting::View < ActionView::Base
|
2
|
+
delegate :protect_against_forgery?, :form_authenticity_token, :url_for, :to => :controller
|
3
|
+
end
|
data/lib/presenting.rb
CHANGED
@@ -1,9 +1,42 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'presenting/engine'
|
4
|
+
|
1
5
|
module Presenting
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
autoload :Attribute, 'presenting/attribute'
|
7
|
+
autoload :Configurable, 'presenting/configurable'
|
8
|
+
autoload :Defaults, 'presenting/defaults'
|
9
|
+
autoload :FieldSet, 'presenting/field_set'
|
10
|
+
autoload :FormHelpers, 'presenting/form_helpers'
|
11
|
+
autoload :Helpers, 'presenting/helpers'
|
12
|
+
autoload :Sanitize, 'presenting/sanitize'
|
13
|
+
autoload :Search, 'presenting/search'
|
14
|
+
autoload :Sorting, 'presenting/sorting'
|
15
|
+
autoload :View, 'presenting/view'
|
16
|
+
|
17
|
+
# copies all assets into the application's public directory
|
18
|
+
# public/stylesheets/presenting and public/javascripts/presenting
|
19
|
+
def self.precache!
|
20
|
+
presenting_dir = __FILE__.sub(/\/lib\/.*/, '') # there must be a better way
|
21
|
+
%w(stylesheets javascripts).each do |asset_type|
|
22
|
+
source_dir = File.join(presenting_dir, 'app', 'assets', asset_type)
|
23
|
+
target_dir = File.join(Rails.application.paths.public.send(asset_type).first, 'presenting')
|
24
|
+
FileUtils.mkdir_p(target_dir)
|
25
|
+
|
26
|
+
Dir[File.join(source_dir, '*')].each do |asset|
|
27
|
+
FileUtils.cp(asset, File.join(target_dir, File.basename(asset)))
|
28
|
+
end
|
7
29
|
end
|
8
30
|
end
|
9
31
|
end
|
32
|
+
|
33
|
+
module Presentation
|
34
|
+
autoload :Base, 'presentation/base'
|
35
|
+
end
|
36
|
+
|
37
|
+
Dir[File.join(File.dirname(__FILE__), 'presentation', '*')].each { |path| require path }
|
38
|
+
|
39
|
+
ActionView::Base.class_eval { include Presenting::Helpers }
|
40
|
+
ActionController::Base.const_set(:Search, Presenting::Search)
|
41
|
+
ActionController::Base.const_set(:Sorting, Presenting::Sorting)
|
42
|
+
ActionView::Helpers::FormBuilder.class_eval { include Presenting::FormHelpers }
|
data/test/assets_test.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
require 'action_controller/test_case'
|
3
|
-
require 'action_controller/integration'
|
4
2
|
|
5
3
|
class Presentation::AssetsControllerTest < ActionController::TestCase
|
6
4
|
|
@@ -25,14 +23,14 @@ class Presentation::AssetsControllerTest < ActionController::TestCase
|
|
25
23
|
def test_retrieving_a_named_stylesheet
|
26
24
|
get :stylesheet, :id => 'grid', :format => 'css'
|
27
25
|
assert_response :success
|
28
|
-
assert_equal @response.body, File.read(File.join(
|
26
|
+
assert_equal @response.body, File.read(File.join('app', 'assets', 'stylesheets', 'grid.css'))
|
29
27
|
end
|
30
28
|
|
31
29
|
def test_retrieving_multiple_named_stylesheets
|
32
30
|
get :stylesheet, :id => 'grid,form', :format => 'css'
|
33
31
|
assert_response :success
|
34
|
-
assert @response.body.include?(File.read(File.join(
|
35
|
-
assert @response.body.include?(File.read(File.join(
|
32
|
+
assert @response.body.include?(File.read(File.join('app', 'assets', 'stylesheets', 'grid.css')))
|
33
|
+
assert @response.body.include?(File.read(File.join('app', 'assets', 'stylesheets', 'form.css')))
|
36
34
|
end
|
37
35
|
|
38
36
|
# javascript
|
@@ -52,7 +50,7 @@ class Presentation::AssetsControllerTest < ActionController::TestCase
|
|
52
50
|
def test_retrieving_multiple_named_javascripts
|
53
51
|
get :javascript, :id => 'grid,search', :format => 'js'
|
54
52
|
assert_response :success
|
55
|
-
assert @response.body.include?(File.read(File.join(
|
56
|
-
assert @response.body.include?(File.read(File.join(
|
53
|
+
assert @response.body.include?(File.read(File.join('app', 'assets', 'javascripts', 'grid.js')))
|
54
|
+
assert @response.body.include?(File.read(File.join('app', 'assets', 'javascripts', 'search.js')))
|
57
55
|
end
|
58
56
|
end
|
data/test/details_test.rb
CHANGED
@@ -28,7 +28,7 @@ class DetailsRenderTest < Presentation::RenderTest
|
|
28
28
|
def setup
|
29
29
|
@presentation = Presentation::Details.new
|
30
30
|
@presentation.presentable = stub('user', :name => 'foo', :email => 'foo@example.com')
|
31
|
-
@presentation.controller = TestController.new
|
31
|
+
@presentation.controller = ActionView::TestCase::TestController.new
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_rendering_a_title
|
data/test/field_search_test.rb
CHANGED
@@ -47,7 +47,7 @@ end
|
|
47
47
|
class FieldSearchRenderingTest < Presentation::RenderTest
|
48
48
|
def setup
|
49
49
|
@presentation = Presentation::FieldSearch.new
|
50
|
-
@presentation.controller = TestController.new
|
50
|
+
@presentation.controller = ActionView::TestCase::TestController.new
|
51
51
|
@presentation.controller.request.path = '/users'
|
52
52
|
end
|
53
53
|
|