puffer 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/.rvmrc +1 -0
  2. data/Gemfile +11 -8
  3. data/Gemfile.lock +117 -103
  4. data/Guardfile +20 -0
  5. data/VERSION +1 -1
  6. data/app/assets/javascripts/puffer/application.js +5 -0
  7. data/{lib/generators/puffer/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/puffer.js +0 -0
  8. data/{lib/generators/puffer/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/rails.js +0 -0
  9. data/{lib/generators/puffer/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/right-autocompleter.js +0 -0
  10. data/{lib/generators/puffer/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/right-calendar.js +0 -0
  11. data/{lib/generators/puffer/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/right.js +0 -0
  12. data/app/assets/stylesheets/puffer/application.css +4 -0
  13. data/{lib/generators/puffer/install/templates/puffer/stylesheets → app/assets/stylesheets/puffer}/puffer.css +2 -1
  14. data/{lib/generators/puffer/install/templates/puffer/stylesheets → app/assets/stylesheets/puffer}/reset.css +0 -0
  15. data/app/controllers/puffer/dashboard.rb +12 -0
  16. data/app/controllers/puffer/{sessions_base.rb → sessions.rb} +1 -2
  17. data/app/helpers/puffer_helper.rb +2 -10
  18. data/app/views/layouts/puffer.html.erb +24 -5
  19. data/app/views/layouts/puffer_dashboard.html.erb +3 -3
  20. data/app/views/layouts/puffer_sessions.html.erb +3 -3
  21. data/app/views/puffer/{_form.html.erb → base/_form.html.erb} +2 -2
  22. data/app/views/puffer/{associated → base/associated}/_many.html.erb +1 -1
  23. data/app/views/puffer/{associated → base/associated}/many.rjs +0 -0
  24. data/app/views/puffer/{associated → base/associated}/one.js.erb +1 -1
  25. data/app/views/puffer/{association → base/association}/_many.html.erb +0 -0
  26. data/app/views/puffer/{edit.html.erb → base/edit.html.erb} +1 -1
  27. data/app/views/puffer/{index.html.erb → base/index.html.erb} +2 -2
  28. data/app/views/puffer/{new.html.erb → base/new.html.erb} +1 -1
  29. data/app/views/puffer/{show.html.erb → base/show.html.erb} +1 -1
  30. data/app/views/{puffer_dashboard → puffer/dashboard}/index.html.erb +0 -0
  31. data/app/views/{puffer_sessions → puffer/sessions}/new.html.erb +0 -0
  32. data/config/locales/puffer.yml +5 -0
  33. data/lib/generators/puffer/install/install_generator.rb +0 -8
  34. data/lib/generators/puffer/install/templates/dashboard_controller.rb +1 -1
  35. data/lib/generators/puffer/install/templates/sessions_controller.rb +1 -1
  36. data/lib/puffer.rb +0 -16
  37. data/lib/puffer/base.rb +8 -3
  38. data/lib/puffer/controller/config.rb +2 -0
  39. data/lib/puffer/controller/dsl.rb +2 -2
  40. data/lib/puffer/controller/generated.rb +4 -4
  41. data/lib/puffer/controller/helpers.rb +1 -1
  42. data/lib/puffer/controller/mutate.rb +0 -14
  43. data/lib/puffer/customs.rb +1 -0
  44. data/lib/puffer/engine.rb +0 -4
  45. data/lib/puffer/extensions/mapper.rb +5 -1
  46. data/lib/puffer/fields.rb +2 -2
  47. data/lib/puffer/fields/field.rb +16 -17
  48. data/lib/puffer/inputs/association.rb +3 -2
  49. data/lib/puffer/resource.rb +13 -12
  50. data/lib/puffer/resource/routing.rb +1 -1
  51. data/lib/puffer/resource/scoping.rb +2 -2
  52. data/puffer.gemspec +63 -126
  53. data/spec/dummy/.rvmrc +1 -0
  54. data/spec/dummy/Rakefile +1 -1
  55. data/spec/dummy/app/assets/images/rails.png +0 -0
  56. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  57. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  58. data/spec/dummy/app/controllers/admin/posts_controller.rb +3 -1
  59. data/spec/dummy/app/controllers/admin/profiles_controller.rb +4 -1
  60. data/spec/dummy/app/controllers/puffer/dashboard_controller.rb +1 -1
  61. data/spec/dummy/app/controllers/puffer/sessions_controller.rb +1 -1
  62. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/spec/dummy/config/application.rb +5 -9
  64. data/spec/dummy/config/boot.rb +5 -7
  65. data/spec/dummy/config/database.yml +4 -1
  66. data/spec/dummy/config/environments/development.rb +4 -3
  67. data/spec/dummy/config/environments/production.rb +17 -12
  68. data/spec/dummy/config/environments/test.rb +5 -1
  69. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  70. data/spec/dummy/config/initializers/session_store.rb +1 -1
  71. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  72. data/spec/dummy/config/locales/en.yml +1 -1
  73. data/spec/dummy/db/seeds.rb +7 -0
  74. data/spec/dummy/public/robots.txt +5 -0
  75. data/spec/fabricators/posts_fabricator.rb +1 -1
  76. data/spec/fabricators/profiles_fabricator.rb +1 -1
  77. data/spec/fabricators/users_fabricator.rb +1 -1
  78. data/spec/lib/resource/routing_spec.rb +5 -5
  79. data/spec/lib/resource_spec.rb +37 -88
  80. data/spec/spec_helper.rb +15 -0
  81. metadata +171 -272
  82. data/app/cells/puffer/base/additional.html.erb +0 -25
  83. data/app/cells/puffer/base_cell.rb +0 -25
  84. data/app/controllers/puffer/dashboard_base.rb +0 -13
  85. data/autotest/discover.rb +0 -2
  86. data/lib/generators/puffer/install/templates/puffer.rb +0 -12
  87. data/lib/puffer/path_set.rb +0 -24
  88. data/spec/dummy/app/views/admin/users/index.html.erb +0 -3
  89. data/spec/dummy/config/initializers/puffer.rb +0 -12
  90. data/spec/dummy/db/schema.rb +0 -83
  91. data/spec/dummy/public/javascripts/application.js +0 -2
  92. data/spec/dummy/public/javascripts/controls.js +0 -965
  93. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  94. data/spec/dummy/public/javascripts/effects.js +0 -1123
  95. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  96. data/spec/dummy/public/javascripts/rails.js +0 -175
  97. data/spec/dummy/public/puffer/javascripts/puffer.js +0 -10
  98. data/spec/dummy/public/puffer/javascripts/rails.js +0 -57
  99. data/spec/dummy/public/puffer/javascripts/right-autocompleter.js +0 -621
  100. data/spec/dummy/public/puffer/javascripts/right-calendar.js +0 -1461
  101. data/spec/dummy/public/puffer/javascripts/right.js +0 -5892
  102. data/spec/dummy/public/puffer/stylesheets/puffer.css +0 -469
  103. data/spec/dummy/public/puffer/stylesheets/reset.css +0 -60
  104. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  105. data/spec/lib/render_fallback_spec.rb +0 -17
@@ -4,16 +4,16 @@
4
4
  <title><%= [@title, 'Puffer'].compact.join(' - ') %></title>
5
5
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
6
6
  <%= csrf_meta_tag %>
7
- <%= puffer_stylesheets %>
7
+ <%= stylesheet_link_tag "puffer/application" %>
8
+ <%= javascript_include_tag "puffer/application" %>
8
9
  <%= yield :stylesheets %>
9
- <%= puffer_javascripts %>
10
10
  <%= yield :javascripts %>
11
11
  </head>
12
12
  <body>
13
13
  <div class="body">
14
14
  <div class="header">
15
15
  <div class="logo">
16
- <%= link_to Puffer.logo, puffer_root_path %>
16
+ <%= link_to t('puffer.logo'), puffer_root_path %>
17
17
  </div>
18
18
  <ul class="namespaces">
19
19
  <% puffer_namespaces do |title, path, current| %>
@@ -4,16 +4,16 @@
4
4
  <title><%= [@title, 'Puffer'].compact.join(' - ') %></title>
5
5
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
6
6
  <%= csrf_meta_tag %>
7
- <%= puffer_stylesheets %>
7
+ <%= stylesheet_link_tag "puffer/application" %>
8
+ <%= javascript_include_tag "puffer/application" %>
8
9
  <%= yield :stylesheets %>
9
- <%= puffer_javascripts %>
10
10
  <%= yield :javascripts %>
11
11
  </head>
12
12
  <body>
13
13
  <div class="body">
14
14
  <div class="header">
15
15
  <div class="logo">
16
- <span><%= Puffer.logo %></span>
16
+ <span><%= t('puffer.logo') %></span>
17
17
  </div>
18
18
  </div>
19
19
  <div class="content sessions">
@@ -5,8 +5,8 @@
5
5
  </ul>
6
6
 
7
7
  <div class="buttons">
8
- <%= f.submit 'Save' %>
9
- <%= f.submit 'Save and exit' %>
8
+ <%= f.submit t('puffer.save') %>
9
+ <%= f.submit t('puffer.save_and_exit') %>
10
10
  <%= link_to 'cancel', (request.referer || resource.collectin_path) %>
11
11
  </div>
12
12
 
@@ -21,7 +21,7 @@
21
21
  </div>
22
22
 
23
23
  <div class="pagination">
24
- <%= will_paginate associated, :renderer => AssociatedLinkRenderer, :ids => ids %>
24
+ <%= paginate associated, :renderer => AssociatedLinkRenderer, :ids => ids %>
25
25
  </div>
26
26
 
27
27
  <div class="popup_content">
@@ -5,7 +5,7 @@
5
5
  <div class="title"><strong><%= record[primary_key] %></strong> — <%= record.to_title %></div>
6
6
  <div class="description">
7
7
  <% @field.association_columns.searchable.each do |column| %>
8
- <div><strong><%= column.label %>:</strong> <%= render_field column, record %></div>
8
+ <div><strong><%= column.human %>:</strong> <%= render_field column, record %></div>
9
9
  <% end %>
10
10
  </div>
11
11
  </li>
@@ -1,6 +1,6 @@
1
1
  <% @title = "Edit #{resource.human}" %>
2
2
  <h1><%= @title %></h1>
3
3
  <%= form_for record, :url => resource.member_path, :html => {:multipart => true} do |f| %>
4
- <%= render :partial => 'terbium/form', :locals => { :f => f, :action => 'edit' } %>
4
+ <%= render :partial => 'form', :locals => { :f => f, :action => 'edit' } %>
5
5
  <% end %>
6
6
 
@@ -1,6 +1,6 @@
1
1
  <% @title = resource.human %>
2
2
  <h1><%= @title %></h1>
3
- <%= will_paginate records, :url => resource.collection_path(:page => '') %>
3
+ <%= paginate records, :url => resource.collection_path(:page => '') %>
4
4
  <% if records.present? %>
5
5
  <table class="list_table">
6
6
  <thead>
@@ -31,5 +31,5 @@
31
31
  <% else %>
32
32
  <p>Sorry, but there is no records in <%= resource.human %></p>
33
33
  <% end %>
34
- <%= will_paginate records, :url => resource.collection_path(:page => '') %>
34
+ <%= paginate records, :url => resource.collection_path(:page => '') %>
35
35
 
@@ -1,6 +1,6 @@
1
1
  <% @title = "New #{resource.human}" %>
2
2
  <h1><%= @title %></h1>
3
3
  <%= form_for record, :url => resource.collection_path, :html => {:multipart => true} do |f| %>
4
- <%= render :partial => 'terbium/form', :locals => { :f => f, :action => 'new' } %>
4
+ <%= render :partial => 'form', :locals => { :f => f, :action => 'new' } %>
5
5
  <% end %>
6
6
 
@@ -12,7 +12,7 @@
12
12
 
13
13
  <% show_fields.each do |field| -%>
14
14
  <li>
15
- <h2><%= field.label %></h2>
15
+ <h2><%= field.human %></h2>
16
16
  <div>
17
17
  <%= render_field field, record %>
18
18
  </div>
@@ -0,0 +1,5 @@
1
+ en:
2
+ puffer:
3
+ save: 'Save'
4
+ save_and_exit: 'Save and exit'
5
+ logout: 'logout'
@@ -1,14 +1,6 @@
1
1
  class Puffer::InstallGenerator < Rails::Generators::Base
2
2
  source_root File.expand_path('../templates', __FILE__)
3
3
 
4
- def generate_assets
5
- directory 'puffer', 'public/puffer'
6
- end
7
-
8
- def generate_config
9
- copy_file 'puffer.rb', 'config/initializers/puffer.rb'
10
- end
11
-
12
4
  def generate_puffer_controllers
13
5
  copy_file 'sessions_controller.rb', 'app/controllers/puffer/sessions_controller.rb'
14
6
  copy_file 'dashboard_controller.rb', 'app/controllers/puffer/dashboard_controller.rb'
@@ -1,3 +1,3 @@
1
- class Puffer::DashboardController < Puffer::DashboardBase
1
+ class Puffer::DashboardController < Puffer::Dashboard
2
2
 
3
3
  end
@@ -1,4 +1,4 @@
1
- class Puffer::SessionsController < Puffer::SessionsBase
1
+ class Puffer::SessionsController < Puffer::Sessions
2
2
  # This is example session controller for puffer authentication.
3
3
  # You can define your own actions.
4
4
  # Also, you can redefine <tt>new<tt> action view as you wish,
data/lib/puffer.rb CHANGED
@@ -1,27 +1,11 @@
1
1
  module Puffer
2
2
 
3
- mattr_accessor :stylesheets
4
- self.stylesheets = %w(reset puffer)
5
-
6
- mattr_accessor :javascripts
7
- self.javascripts = %w(right right-calendar right-autocompleter rails puffer)
8
-
9
- mattr_accessor :logo
10
- self.logo = 'Puffer'
11
-
12
- def self.setup
13
- yield self
14
- end
15
-
16
3
  def self.customs
17
4
  Puffer::Customs
18
5
  end
19
6
 
20
7
  end
21
8
 
22
- require 'will_paginate'
23
- require 'cells'
24
-
25
9
  require 'puffer/engine'
26
10
  require 'puffer/extensions/activerecord'
27
11
  require 'puffer/extensions/controller'
data/lib/puffer/base.rb CHANGED
@@ -3,7 +3,6 @@ module Puffer
3
3
  unloadable
4
4
 
5
5
  pufferize!
6
- view_paths_fallbacks :puffer
7
6
  define_fields :index, :show, :form, :create, :update
8
7
 
9
8
  respond_to :html, :js
@@ -27,13 +26,13 @@ module Puffer
27
26
  def create
28
27
  @record = resource.new_member
29
28
  @record.save
30
- respond_with @record, :location => resource.collection_path
29
+ respond_with @record, :location => puffer_saving_location
31
30
  end
32
31
 
33
32
  def update
34
33
  @record = resource.member
35
34
  @record.update_attributes resource.attributes
36
- respond_with @record, :location => resource.collection_path
35
+ respond_with @record, :location => puffer_saving_location
37
36
  end
38
37
 
39
38
  def destroy
@@ -42,5 +41,11 @@ module Puffer
42
41
  redirect_to (request.referrer || resource.collection_path)
43
42
  end
44
43
 
44
+ private
45
+
46
+ def puffer_saving_location
47
+ params[:commit] == t('puffer.save') ? resource.edit_path(record) : resource.collection_path
48
+ end
49
+
45
50
  end
46
51
  end
@@ -54,6 +54,8 @@ module Puffer
54
54
  controller.send "#{method_name}=", args.first
55
55
  elsif controller.respond_to?(method_name)
56
56
  controller.send method_name
57
+ else
58
+ super
57
59
  end
58
60
  end
59
61
 
@@ -53,8 +53,8 @@ module Puffer
53
53
  end
54
54
  end
55
55
 
56
- def field name, options = {}
57
- field = @_fields.field(name, model, options) if @_fields
56
+ def field name, options = {}, &block
57
+ field = @_fields.field(name, model, options, &block) if @_fields
58
58
  generate_association_actions field if field.reflection
59
59
  #generate_change_actions field if field.toggable?
60
60
  end
@@ -19,7 +19,7 @@ module Puffer
19
19
  @field = field
20
20
  @record = resource.member if params[:id]
21
21
  @records = field.reflection.klass.includes(field.association_columns.includes).where(field.association_columns.searches(params[:search])).limit(100).all
22
- render 'puffer/associated/one'
22
+ render :action => 'associated/one'
23
23
  end
24
24
 
25
25
  collection do
@@ -32,7 +32,7 @@ module Puffer
32
32
  @record = resource.member
33
33
  @records = field.association.klass.scoped(:conditions => {:id => params[:ids]}).scoped(:conditions => search_query(field.association_fields)).paginate(:page => params[:page], :include => includes(field.association_fields))
34
34
  @field = field
35
- render 'puffer/associated/many'
35
+ render :action => 'associated/many'
36
36
  end
37
37
 
38
38
  define_method "associated_#{field}_choosing" do
@@ -40,7 +40,7 @@ module Puffer
40
40
  @records = field.association.klass.scoped(:conditions => search_query(field.association_fields)).paginate(:page => params[:page], :include => includes(field.association_fields))
41
41
  @choosen = field.association.klass.scoped(:conditions => {:id => params[:ids]}).scoped(:conditions => search_query(field.association_fields)).paginate(:page => params[:page], :include => includes(field.association_fields))
42
42
  @field = field
43
- render 'puffer/associated/many'
43
+ render :action => 'associated/many'
44
44
  end
45
45
 
46
46
  collection do
@@ -54,7 +54,7 @@ module Puffer
54
54
  @record = model.find params[:id]
55
55
  @field = field
56
56
  @record.toggle! field.name.to_sym
57
- render 'puffer/toggle'
57
+ render :action => 'toggle'
58
58
  end
59
59
  end
60
60
 
@@ -13,7 +13,7 @@ module Puffer
13
13
  module InstanceMethods
14
14
 
15
15
  def resource
16
- @resource ||= Puffer::Resource.new params, request
16
+ @resource ||= Puffer::Resource.new params, self
17
17
  end
18
18
 
19
19
  def record
@@ -43,20 +43,6 @@ module Puffer
43
43
  @model ||= model_name.camelize.constantize rescue nil
44
44
  end
45
45
 
46
- def view_paths_fallbacks *args
47
- temp = Puffer::PathSet.new view_paths
48
- temp._fallbacks = args.flatten
49
- self.view_paths = temp
50
- end
51
-
52
- def view_paths_fallbacks_prepend *args
53
- view_paths_fallbacks args, view_paths._fallbacks
54
- end
55
-
56
- def view_paths_fallbacks_append *args
57
- view_paths_fallbacks view_paths._fallbacks, args
58
- end
59
-
60
46
  end
61
47
 
62
48
  end
@@ -61,3 +61,4 @@ module Puffer
61
61
 
62
62
  end
63
63
  end
64
+
data/lib/puffer/engine.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  module Puffer
2
2
  class Engine < Rails::Engine
3
3
  config.autoload_paths << File.join(root, 'lib')
4
-
5
- initializer 'puffer.add_cells_paths', :after => :add_view_paths do
6
- ::Cell::Base.prepend_view_path(Cells::DEFAULT_VIEW_PATHS.map { |path| File.join(root, path) })
7
- end
8
4
  end
9
5
  end
@@ -160,7 +160,11 @@ module Puffer
160
160
  include InstanceMethods
161
161
 
162
162
  alias_method_chain :clear!, :puffer
163
- attr_accessor_with_default :puffer, ActiveSupport::OrderedHash.new
163
+ attr_writer :puffer
164
+
165
+ def puffer
166
+ @puffer ||= ActiveSupport::OrderedHash.new
167
+ end
164
168
  end
165
169
  end
166
170
 
data/lib/puffer/fields.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Puffer
2
2
  class Fields < Array
3
3
 
4
- def field *args
5
- push Field.new(*args)
4
+ def field *args, &block
5
+ push Field.new(*args, &block)
6
6
  last
7
7
  end
8
8
 
@@ -2,12 +2,18 @@ module Puffer
2
2
  class Fields
3
3
  class Field
4
4
 
5
- attr_accessor :resource, :field, :options
5
+ attr_accessor :resource, :field_name, :options, :fields
6
6
 
7
- def initialize field, *resource_and_options
8
- @field = field.to_s
7
+ def initialize field_name, *resource_and_options, &block
8
+ @field_name = field_name.to_s
9
9
  @options = resource_and_options.extract_options!
10
10
  @resource = resource_and_options.first
11
+ @fields = Puffer::Fields.new
12
+ block.bind(self).call if block
13
+ end
14
+
15
+ def field name, options = {}, &block
16
+ @fields.field(name, swallow_nil{reflection.klass}, options, &block)
11
17
  end
12
18
 
13
19
  def native?
@@ -15,15 +21,15 @@ module Puffer
15
21
  end
16
22
 
17
23
  def name
18
- @name ||= field.split('.').last
24
+ @name ||= field_name.split('.').last
19
25
  end
20
26
 
21
27
  def path
22
- @path ||= field.split('.')[0..-2].join('.')
28
+ @path ||= field_name.split('.')[0..-2].join('.')
23
29
  end
24
30
 
25
- def label
26
- @label ||= resource.human_attribute_name(field)
31
+ def human
32
+ @human ||= model && model.human_attribute_name(name)
27
33
  end
28
34
 
29
35
  def order
@@ -35,7 +41,7 @@ module Puffer
35
41
  end
36
42
 
37
43
  def to_s
38
- field
44
+ field_name
39
45
  end
40
46
 
41
47
  def reflection
@@ -56,7 +62,7 @@ module Puffer
56
62
 
57
63
  def model
58
64
  @model ||= begin
59
- associations = field.split('.')
65
+ associations = field_name.split('.')
60
66
  associations.pop
61
67
  temp = resource
62
68
  while temp.reflect_on_association(association = swallow_nil{associations.shift.to_sym}) do
@@ -67,14 +73,7 @@ module Puffer
67
73
  end
68
74
 
69
75
  def association_columns
70
- raise "Can`t find records for association building. Please set :columns option for '#{field}' field." unless options[:columns].present?
71
- @reflection_fields ||= begin
72
- fields = Puffer::Fields.new
73
- options[:columns].each do |field_name|
74
- fields.field field_name, reflection.klass
75
- end
76
- fields
77
- end
76
+ @association_columns ||= fields
78
77
  end
79
78
 
80
79
  def column
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  module Puffer
2
3
  module Inputs
3
4
  class Association < Puffer::Inputs::Base
@@ -11,7 +12,7 @@ module Puffer
11
12
  'data-autocompleter' => "{url: '#{resource.collection_path(:action => "associated_#{field}_choosing")}', onDone: association_done}"
12
13
  )}
13
14
  <div class="association_clear">×</div>
14
- #{builder.hidden_field field.reflection.primary_key_name}
15
+ #{builder.hidden_field field.reflection.foreign_key}
15
16
  </div>
16
17
  INPUT
17
18
  end
@@ -28,7 +29,7 @@ module Puffer
28
29
  end
29
30
 
30
31
  def error
31
- builder.object.errors[field.reflection.primary_key_name.to_sym].first ||
32
+ builder.object.errors[field.reflection.foreign_key.to_sym].first ||
32
33
  builder.object.errors[field.name.to_sym].first.presence
33
34
  end
34
35