best_in_place 0.2.3 → 1.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.
Files changed (31) hide show
  1. data/.travis.yml +5 -0
  2. data/Gemfile +1 -0
  3. data/best_in_place.gemspec +2 -1
  4. data/{test_app/public → lib/assets}/javascripts/best_in_place.js +1 -3
  5. data/{public → lib/assets}/javascripts/jquery.purr.js +0 -0
  6. data/lib/best_in_place.rb +1 -3
  7. data/lib/best_in_place/engine.rb +7 -0
  8. data/lib/best_in_place/helper.rb +1 -2
  9. data/lib/best_in_place/test_helpers.rb +8 -21
  10. data/lib/best_in_place/version.rb +1 -1
  11. data/spec/helpers/best_in_place_spec.rb +2 -12
  12. data/spec/integration/double_init_spec.rb +2 -2
  13. data/spec/integration/js_spec.rb +12 -12
  14. data/test_app/Gemfile +10 -3
  15. data/test_app/{public → app/assets}/images/red_pen.png +0 -0
  16. data/test_app/{public → app/assets}/javascripts/application.js +3 -2
  17. data/test_app/{public → app/assets}/stylesheets/.gitkeep +0 -0
  18. data/test_app/{public → app/assets}/stylesheets/scaffold.css +0 -0
  19. data/test_app/{public → app/assets}/stylesheets/style.css +0 -0
  20. data/test_app/app/views/layouts/application.html.erb +1 -1
  21. data/test_app/config/application.rb +12 -3
  22. metadata +32 -29
  23. data/lib/best_in_place/utils.rb +0 -15
  24. data/lib/generators/best_in_place/setup_generator.rb +0 -11
  25. data/public/javascripts/best_in_place.js +0 -481
  26. data/public/javascripts/jquery-1.4.4.js +0 -7179
  27. data/spec/integration/text_area_spec.rb +0 -30
  28. data/test_app/public/images/rails.png +0 -0
  29. data/test_app/public/javascripts/jquery-1.4.4.min.js +0 -167
  30. data/test_app/public/javascripts/jquery.purr.js +0 -161
  31. data/test_app/public/javascripts/rails.js +0 -148
@@ -9,3 +9,8 @@ env: "RAILS_ENV=test DISPLAY=:99.0"
9
9
  before_script:
10
10
  - "sh -c 'cd test_app && bundle && bundle exec rake db:drop db:migrate'"
11
11
  - "sh -e /etc/init.d/xvfb start"
12
+
13
+ branches:
14
+ only:
15
+ - master
16
+ - rails-3.0
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem 'sqlite3-ruby', :require => 'sqlite3'
7
+ gem 'jquery-rails'
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "rails", ">= 3.0.0"
22
+ s.add_dependency "rails", "~> 3.1.0"
23
+ s.add_dependency "jquery-rails"
23
24
 
24
25
  s.add_development_dependency "rspec-rails", "~> 2.7.0"
25
26
  s.add_development_dependency "nokogiri", ">= 1.5.0"
@@ -339,9 +339,7 @@ BestInPlaceEditor.forms = {
339
339
 
340
340
  jQuery.fn.best_in_place = function() {
341
341
  this.each(function(){
342
- if (!jQuery(this).data('bestInPlaceEditor')) {
343
- jQuery(this).data('bestInPlaceEditor', new BestInPlaceEditor(this));
344
- }
342
+ jQuery(this).data('bestInPlaceEditor', new BestInPlaceEditor(this));
345
343
  });
346
344
  return this;
347
345
  };
@@ -1,8 +1,6 @@
1
- require "best_in_place/utils"
2
1
  require "best_in_place/helper"
2
+ require "best_in_place/engine"
3
3
 
4
4
  module BestInPlace
5
5
  autoload :TestHelpers, "best_in_place/test_helpers"
6
6
  end
7
-
8
- ActionView::Base.send(:include, BestInPlace::BestInPlaceHelpers)
@@ -0,0 +1,7 @@
1
+ module BestInPlace
2
+ class Engine < Rails::Engine
3
+ initializer "setup for rails" do
4
+ ActionView::Base.send(:include, BestInPlace::BestInPlaceHelpers)
5
+ end
6
+ end
7
+ end
@@ -1,6 +1,5 @@
1
1
  module BestInPlace
2
2
  module BestInPlaceHelpers
3
-
4
3
  def best_in_place(object, field, opts = {})
5
4
  opts[:type] ||= :input
6
5
  opts[:collection] ||= []
@@ -21,7 +20,7 @@ module BestInPlace
21
20
  collection = opts[:collection].to_json
22
21
  end
23
22
  out = "<span class='best_in_place'"
24
- out << " id='#{BestInPlace::Utils.build_best_in_place_id(object, field)}'"
23
+ out << " id='best_in_place_#{object.class.to_s.gsub("::", "_").underscore}_#{field}'"
25
24
  out << " data-url='#{opts[:path].blank? ? url_for(object).to_s : url_for(opts[:path])}'"
26
25
  out << " data-object='#{object.class.to_s.gsub("::", "_").underscore}'"
27
26
  out << " data-collection='#{collection}'" unless collection.blank?
@@ -1,37 +1,24 @@
1
1
  module BestInPlace
2
2
  module TestHelpers
3
-
4
- def bip_area(model, attr, new_value)
5
- id = BestInPlace::Utils.build_best_in_place_id model, attr
6
- page.execute_script <<-JS
7
- $("##{id}").click();
8
- $("##{id} form textarea").val('#{new_value}');
9
- $("##{id} form textarea").blur();
10
- JS
11
- end
12
-
13
3
  def bip_text(model, attr, new_value)
14
- id = BestInPlace::Utils.build_best_in_place_id model, attr
15
4
  page.execute_script <<-JS
16
- $("##{id}").click();
17
- $("##{id} input[name='#{attr}']").val('#{new_value}');
18
- $("##{id} form").submit();
5
+ $("#best_in_place_#{model}_#{attr}").click();
6
+ $("#best_in_place_#{model}_#{attr} input[name='#{attr}']").val('#{new_value}');
7
+ $("#best_in_place_#{model}_#{attr} form").submit();
19
8
  JS
20
9
  end
21
10
 
22
11
  def bip_bool(model, attr)
23
- id = BestInPlace::Utils.build_best_in_place_id model, attr
24
- page.execute_script("$('##{id}').click();")
12
+ page.execute_script("$('#best_in_place_#{model}_#{attr}').click();")
25
13
  end
26
14
 
27
15
  def bip_select(model, attr, name)
28
- id = BestInPlace::Utils.build_best_in_place_id model, attr
29
16
  page.execute_script <<-JS
30
17
  (function() {
31
- $("##{id}").click();
32
- var opt_value = $("##{id} select option:contains('#{name}')").attr('value');
33
- $("##{id} select option[value='" + opt_value + "']").attr('selected', true);
34
- $("##{id} select").change();
18
+ $("#best_in_place_#{model}_#{attr}").click();
19
+ var opt_value = $("#best_in_place_#{model}_#{attr} select option:contains('#{name}')").attr('value');
20
+ $("#best_in_place_#{model}_#{attr} select option[value='" + opt_value + "']").attr('selected', true);
21
+ $("#best_in_place_#{model}_#{attr} select").change();
35
22
  })();
36
23
  JS
37
24
  end
@@ -1,3 +1,3 @@
1
1
  module BestInPlace
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -26,18 +26,8 @@ describe BestInPlace::BestInPlaceHelpers do
26
26
  @span = nk.css("span")
27
27
  end
28
28
 
29
- context "when it's an ActiveRecord model" do
30
- it "should have a proper id" do
31
- @span.attribute("id").value.should == "best_in_place_user_#{@user.id}_name"
32
- end
33
- end
34
-
35
- context "when it's not an AR model" do
36
- it "shold generate an html id without any id" do
37
- nk = Nokogiri::HTML.parse(helper.best_in_place [1,2,3], :first, :path => @user)
38
- span = nk.css("span")
39
- span.attribute("id").value.should == "best_in_place_array_first"
40
- end
29
+ it "should have a proper id" do
30
+ @span.attribute("id").value.should == "best_in_place_user_name"
41
31
  end
42
32
 
43
33
  it "should have the best_in_place class" do
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
3
 
4
- describe "Double initialization bug", :js => true do
4
+ describe "Double initialization bug", :js => true, :pending => true do
5
5
  before do
6
6
  @user = User.new :name => "Lucia",
7
7
  :last_name => "Napoli",
@@ -21,7 +21,7 @@ describe "Double initialization bug", :js => true do
21
21
  page.should have_content("No thanks")
22
22
  end
23
23
 
24
- bip_bool @user, :receive_email
24
+ bip_bool :user, :receive_email
25
25
 
26
26
  visit double_init_user_path(@user)
27
27
  within("#receive_email") do
@@ -35,14 +35,14 @@ describe "JS behaviour", :js => true do
35
35
  end
36
36
  end
37
37
 
38
- it "should be able to use bip_text to update a text field" do
38
+ it "should be able to use the bip_text to update a text field" do
39
39
  @user.save!
40
40
  visit user_path(@user)
41
41
  within("#email") do
42
42
  page.should have_content("lucianapoli@gmail.com")
43
43
  end
44
44
 
45
- bip_text @user, :email, "new@email.com"
45
+ bip_text :user, :email, "new@email.com"
46
46
 
47
47
  visit user_path(@user)
48
48
  within("#email") do
@@ -54,13 +54,13 @@ describe "JS behaviour", :js => true do
54
54
  @user.save!
55
55
  visit user_path(@user)
56
56
 
57
- bip_text @user, :email, "new@email.com"
57
+ bip_text :user, :email, "new@email.com"
58
58
 
59
59
  within("#email") do
60
60
  page.should have_content("new@email.com")
61
61
  end
62
62
 
63
- bip_text @user, :email, "new_two@email.com"
63
+ bip_text :user, :email, "new_two@email.com"
64
64
 
65
65
  within("#email") do
66
66
  page.should have_content("new_two@email.com")
@@ -76,10 +76,10 @@ describe "JS behaviour", :js => true do
76
76
  @user.save!
77
77
  visit user_path(@user)
78
78
 
79
- bip_text @user, :email, "wrong format"
79
+ bip_text :user, :email, "wrong format"
80
80
  page.should have_content("Email has wrong email format")
81
81
 
82
- bip_text @user, :email, "another@email.com"
82
+ bip_text :user, :email, "another@email.com"
83
83
  within("#email") do
84
84
  page.should have_content("another@email.com")
85
85
  end
@@ -97,7 +97,7 @@ describe "JS behaviour", :js => true do
97
97
  page.should have_content("Italy")
98
98
  end
99
99
 
100
- bip_select @user, :country, "France"
100
+ bip_select :user, :country, "France"
101
101
 
102
102
  visit user_path(@user)
103
103
  within("#country") do
@@ -113,7 +113,7 @@ describe "JS behaviour", :js => true do
113
113
  page.should have_content("No thanks")
114
114
  end
115
115
 
116
- bip_bool @user, :receive_email
116
+ bip_bool :user, :receive_email
117
117
 
118
118
  visit user_path(@user)
119
119
  within("#receive_email") do
@@ -125,7 +125,7 @@ describe "JS behaviour", :js => true do
125
125
  @user.save!
126
126
  visit user_path(@user)
127
127
 
128
- bip_text @user, :address, ""
128
+ bip_text :user, :address, ""
129
129
  page.should have_content("Address can't be blank")
130
130
  within("#address") do
131
131
  page.should have_content("Via Roma 99")
@@ -136,7 +136,7 @@ describe "JS behaviour", :js => true do
136
136
  @user.save!
137
137
  visit user_path(@user)
138
138
 
139
- bip_text @user, :last_name, "a"
139
+ bip_text :user, :last_name, "a"
140
140
  page.should have_content("last_name has invalid length")
141
141
  end
142
142
 
@@ -144,13 +144,13 @@ describe "JS behaviour", :js => true do
144
144
  @user.save!
145
145
  visit user_path(@user)
146
146
 
147
- bip_text @user, :last_name, "a"
147
+ bip_text :user, :last_name, "a"
148
148
 
149
149
  within("#last_name") do
150
150
  page.should have_content("Napoli")
151
151
  end
152
152
 
153
- bip_text @user, :last_name, "Another"
153
+ bip_text :user, :last_name, "Another"
154
154
 
155
155
  within("#last_name") do
156
156
  page.should have_content("Another")
@@ -1,7 +1,14 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '~> 3.0.0'
4
-
5
- gem 'sqlite3-ruby', :require => 'sqlite3'
3
+ gem 'rails', '~> 3.1.0'
4
+ gem 'sqlite3'
6
5
 
7
6
  gem 'best_in_place', :path => ".."
7
+
8
+ gem 'jquery-rails'
9
+
10
+ group :assets do
11
+ gem 'sass-rails', '~> 3.1.4'
12
+ gem 'coffee-rails', '~> 3.1.1'
13
+ gem 'uglifier', '>= 1.0.3'
14
+ end
@@ -1,5 +1,6 @@
1
- // Place your application-specific JavaScript functions and classes here
2
- // This file is automatically included by javascript_include_tag :defaults
1
+ //= require jquery
2
+ //= require best_in_place
3
+ //= require jquery.purr
3
4
 
4
5
  $(document).ready(function() {
5
6
  /* Activating Best In Place */
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <title>Best In Place TEST APP</title>
5
5
  <%= stylesheet_link_tag "scaffold", "style" %>
6
- <%= javascript_include_tag "jquery-1.4.4.min", "rails", "jquery.purr", "best_in_place", "application" %>
6
+ <%= javascript_include_tag "application" %>
7
7
  <%= csrf_meta_tag %>
8
8
  </head>
9
9
  <body>
@@ -2,9 +2,12 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- # If you have a Gemfile, require the gems listed there, including any gems
6
- # you've limited to :test, :development, or :production.
7
- Bundler.require(:default, Rails.env) if defined?(Bundler)
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
8
11
 
9
12
  module BipApp
10
13
  class Application < Rails::Application
@@ -38,5 +41,11 @@ module BipApp
38
41
 
39
42
  # Configure sensitive parameters which will be filtered from the log file.
40
43
  config.filter_parameters += [:password]
44
+
45
+ # Enable the asset pipeline
46
+ config.assets.enabled = true
47
+
48
+ # Version of your assets, change this if you want to expire all your assets
49
+ config.assets.version = '1.0'
41
50
  end
42
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: best_in_place
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000 Z
12
+ date: 2011-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &73120460 !ruby/object:Gem::Requirement
16
+ requirement: &81861640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *81861640
25
+ - !ruby/object:Gem::Dependency
26
+ name: jquery-rails
27
+ requirement: &81861380 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
20
31
  - !ruby/object:Gem::Version
21
- version: 3.0.0
32
+ version: '0'
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *73120460
35
+ version_requirements: *81861380
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec-rails
27
- requirement: &73117090 !ruby/object:Gem::Requirement
38
+ requirement: &81860990 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: 2.7.0
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *73117090
46
+ version_requirements: *81860990
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: nokogiri
38
- requirement: &73114350 !ruby/object:Gem::Requirement
49
+ requirement: &81860690 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 1.5.0
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *73114350
57
+ version_requirements: *81860690
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: capybara
49
- requirement: &73139010 !ruby/object:Gem::Requirement
60
+ requirement: &81860440 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: 1.0.1
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *73139010
68
+ version_requirements: *81860440
58
69
  description: BestInPlace is a jQuery script and a Rails 3 helper that provide the
59
70
  method best_in_place to display any object field easily editable for the user by
60
71
  just clicking on it. It supports input data, text data, boolean data and custom
@@ -72,24 +83,26 @@ files:
72
83
  - README.md
73
84
  - Rakefile
74
85
  - best_in_place.gemspec
86
+ - lib/assets/javascripts/best_in_place.js
87
+ - lib/assets/javascripts/jquery.purr.js
75
88
  - lib/best_in_place.rb
89
+ - lib/best_in_place/engine.rb
76
90
  - lib/best_in_place/helper.rb
77
91
  - lib/best_in_place/test_helpers.rb
78
- - lib/best_in_place/utils.rb
79
92
  - lib/best_in_place/version.rb
80
- - lib/generators/best_in_place/setup_generator.rb
81
- - public/javascripts/best_in_place.js
82
- - public/javascripts/jquery-1.4.4.js
83
- - public/javascripts/jquery.purr.js
84
93
  - spec/helpers/best_in_place_spec.rb
85
94
  - spec/integration/double_init_spec.rb
86
95
  - spec/integration/js_spec.rb
87
- - spec/integration/text_area_spec.rb
88
96
  - spec/spec_helper.rb
89
97
  - test_app/Gemfile
90
98
  - test_app/Gemfile.lock
91
99
  - test_app/README
92
100
  - test_app/Rakefile
101
+ - test_app/app/assets/images/red_pen.png
102
+ - test_app/app/assets/javascripts/application.js
103
+ - test_app/app/assets/stylesheets/.gitkeep
104
+ - test_app/app/assets/stylesheets/scaffold.css
105
+ - test_app/app/assets/stylesheets/style.css
93
106
  - test_app/app/controllers/application_controller.rb
94
107
  - test_app/app/controllers/users_controller.rb
95
108
  - test_app/app/helpers/application_helper.rb
@@ -129,17 +142,7 @@ files:
129
142
  - test_app/public/422.html
130
143
  - test_app/public/500.html
131
144
  - test_app/public/favicon.ico
132
- - test_app/public/images/rails.png
133
- - test_app/public/images/red_pen.png
134
- - test_app/public/javascripts/application.js
135
- - test_app/public/javascripts/best_in_place.js
136
- - test_app/public/javascripts/jquery-1.4.4.min.js
137
- - test_app/public/javascripts/jquery.purr.js
138
- - test_app/public/javascripts/rails.js
139
145
  - test_app/public/robots.txt
140
- - test_app/public/stylesheets/.gitkeep
141
- - test_app/public/stylesheets/scaffold.css
142
- - test_app/public/stylesheets/style.css
143
146
  - test_app/script/rails
144
147
  - test_app/test/fixtures/users.yml
145
148
  - test_app/test/functional/users_controller_test.rb
@@ -162,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
165
  version: '0'
163
166
  segments:
164
167
  - 0
165
- hash: -48281395
168
+ hash: 151823247
166
169
  required_rubygems_version: !ruby/object:Gem::Requirement
167
170
  none: false
168
171
  requirements:
@@ -171,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
174
  version: '0'
172
175
  segments:
173
176
  - 0
174
- hash: -48281395
177
+ hash: 151823247
175
178
  requirements: []
176
179
  rubyforge_project: best_in_place
177
180
  rubygems_version: 1.8.10