jipe 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Add dependencies to develop your gem here.
4
- # Include everything needed to run rake, tests, features, etc.
5
- group :development do
6
- gem "bundler", "~> 1.0.0"
7
- gem "jeweler", "~> 1.5.2"
8
- end
3
+ # Specify your gem's dependencies in jipe.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nat Budin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Jipe
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jipe'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jipe
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,47 +1 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "jipe"
16
- gem.homepage = "http://github.com/nbudin/jipe"
17
- gem.license = "MIT"
18
- gem.summary = %Q{RESTful In-place editors for Rails using Jester}
19
- gem.email = "natbudin@gmail.com"
20
- gem.authors = ["Nat Budin"]
21
- # Include your dependencies below. Runtime dependencies are required when using your gem,
22
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
23
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
24
- # gem.add_development_dependency 'rspec', '> 1.2.3'
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- require 'rake/rdoctask'
30
- desc 'Default: run unit tests.'
31
- task :default => :test
32
-
33
- desc 'Test the jipe plugin.'
34
- Rake::TestTask.new(:test) do |t|
35
- t.libs << 'lib'
36
- t.pattern = 'test/**/*_test.rb'
37
- t.verbose = true
38
- end
39
-
40
- desc 'Generate documentation for the jipe plugin.'
41
- Rake::RDocTask.new(:rdoc) do |rdoc|
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = 'Jipe'
44
- rdoc.options << '--line-numbers' << '--inline-source'
45
- rdoc.rdoc_files.include('README')
46
- rdoc.rdoc_files.include('lib/**/*.rb')
47
- end
1
+ require "bundler/gem_tasks"
@@ -1,62 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jipe/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{jipe}
8
- s.version = "1.0.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jipe"
8
+ spec.version = Jipe::VERSION
9
+ spec.authors = ["Nat Budin"]
10
+ spec.email = ["natbudin@gmail.com"]
11
+ spec.description = %q{An in-place editor for Jester}
12
+ spec.summary = %q{A clone of Prototype's in-place edit controls for Thoughtbot's jester.js. You might not wanna use this now that jQuery exists, but, in case you do, here it is.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Nat Budin"]
12
- s.date = %q{2011-03-15}
13
- s.email = %q{natbudin@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README"
16
- ]
17
- s.files = [
18
- "Gemfile",
19
- "README",
20
- "Rakefile",
21
- "app/controllers/jipe_controller.rb",
22
- "app/views/jipe/jester.js.erb",
23
- "app/views/jipe/jipe.js.erb",
24
- "assets/images/edit-field.png",
25
- "assets/javascripts/jester.js",
26
- "assets/javascripts/jipe.js",
27
- "generators/jipe/USAGE",
28
- "generators/jipe/jipe_generator.rb",
29
- "generators/jipe/templates/edit-field.png",
30
- "init.rb",
31
- "install.rb",
32
- "lib/jipe.rb",
33
- "rails/init.rb",
34
- "tasks/jipe_tasks.rake",
35
- "test/jipe_test.rb",
36
- "uninstall.rb"
37
- ]
38
- s.homepage = %q{http://github.com/nbudin/jipe}
39
- s.licenses = ["MIT"]
40
- s.require_paths = ["lib"]
41
- s.rubygems_version = %q{1.5.0}
42
- s.summary = %q{RESTful In-place editors for Rails using Jester}
43
- s.test_files = [
44
- "test/jipe_test.rb"
45
- ]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
46
20
 
47
- if s.respond_to? :specification_version then
48
- s.specification_version = 3
49
-
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
52
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
53
- else
54
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
56
- end
57
- else
58
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
- end
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rails", ">= 3.0.0"
61
24
  end
62
-
@@ -1,138 +1,146 @@
1
- # Jipe
1
+ require 'jipe/version'
2
2
 
3
3
  module Jipe
4
- def jipe_id_for(record, field, options = {})
5
- options = {
6
- :class => record.class.to_s,
7
- :id => nil }.update(options || {})
8
- rclass = options[:class]
9
- if options[:id]
10
- return options[:id]
11
- else
12
- return "#{rclass.downcase}_#{record.id}_#{field}"
4
+ class Engine < Rails::Engine
5
+ initializer 'jipe.extend_helpers' do
6
+ ActionView::Base.send :include, Jipe::Helpers
13
7
  end
14
8
  end
15
-
16
- def jipe_editor_for(record, field, options = {})
17
- options = { :external_control => true,
18
- :class => record.class.to_s,
19
- :rows => 1 }.update(options || {})
20
- rclass = options[:class]
21
- outstr = <<-ENDDOC
22
- <script type="text/javascript">
23
- new Jipe.InPlaceEditor("#{jipe_id_for(record, field, options)}",
24
- #{rclass}, #{record.id}, #{field.to_json}, {
25
- ENDDOC
26
- if options[:external_control]
27
- outstr << "externalControl: 'edit_#{jipe_id_for(record, field, options)}', "
28
- options.delete(:external_control)
29
- end
30
- if options[:on_complete]
31
- outstr << "onComplete: #{options[:on_complete]}, "
32
- options.delete(:on_complete)
33
- end
34
- if protect_against_forgery?
35
- outstr << "authenticityToken: '#{form_authenticity_token}', "
9
+
10
+ module Helpers
11
+ def jipe_id_for(record, field, options = {})
12
+ options = {
13
+ :class => record.class.to_s,
14
+ :id => nil }.update(options || {})
15
+ rclass = options[:class]
16
+ if options[:id]
17
+ return options[:id]
18
+ else
19
+ return "#{rclass.downcase}_#{record.id}_#{field}"
20
+ end
36
21
  end
37
- outstr << "rows: #{options[:rows]},"
38
- options.delete(:rows)
39
- options.delete(:id)
22
+
23
+ def jipe_editor_for(record, field, options = {})
24
+ options = { :external_control => true,
25
+ :class => record.class.to_s,
26
+ :rows => 1 }.update(options || {})
27
+ rclass = options[:class]
28
+ outstr = <<-ENDDOC
29
+ <script type="text/javascript">
30
+ new Jipe.InPlaceEditor("#{jipe_id_for(record, field, options)}",
31
+ #{rclass}, #{record.id}, #{field.to_json}, {
32
+ ENDDOC
33
+ if options[:external_control]
34
+ outstr << "externalControl: 'edit_#{jipe_id_for(record, field, options)}', "
35
+ options.delete(:external_control)
36
+ end
37
+ if options[:on_complete]
38
+ outstr << "onComplete: #{options[:on_complete]}, "
39
+ options.delete(:on_complete)
40
+ end
41
+ if protect_against_forgery?
42
+ outstr << "authenticityToken: '#{form_authenticity_token}', "
43
+ end
44
+ outstr << "rows: #{options[:rows]},"
45
+ options.delete(:rows)
46
+ options.delete(:id)
40
47
 
41
- # everything else is ajax options
42
- outstr << "ajaxOptions: {"
43
- options.each_pair do |k, v|
44
- outstr << "'#{escape_javascript k.to_s}': '#{escape_javascript v.to_s}',"
45
- end
46
- unless options[:attributes]
47
- outstr << "'attributes[]': '#{escape_javascript field.to_s}'"
48
- end
48
+ # everything else is ajax options
49
+ outstr << "ajaxOptions: {"
50
+ options.each_pair do |k, v|
51
+ outstr << "'#{escape_javascript k.to_s}': '#{escape_javascript v.to_s}',"
52
+ end
53
+ unless options[:attributes]
54
+ outstr << "'attributes[]': '#{escape_javascript field.to_s}'"
55
+ end
49
56
 
50
- outstr << "}});\n</script>"
51
- return outstr
52
- end
57
+ outstr << "}});\n</script>"
58
+ return outstr.html_safe
59
+ end
53
60
 
54
- def jipe_editor(record, field, options = {})
55
- options = { :external_control => true,
56
- :class => record.class.to_s,
57
- :rows => 1,
58
- :editing => true,
59
- :on_complete => nil }.update(options || {})
60
- rclass = options[:class]
61
- outstr = <<-ENDDOC
62
- <span id="#{jipe_id_for(record, field, options)}">
63
- #{record.send(field).to_s}
64
- </span>
65
- ENDDOC
66
- if options[:editing]
67
- outstr += <<-ENDDOC
68
- #{ options[:external_control] ? image_tag("jipe/edit-field.png",
69
- { :id => "edit_#{jipe_id_for(record, field, options)}" }) : "" }
70
- #{ jipe_editor_for(record, field, options)}
61
+ def jipe_editor(record, field, options = {})
62
+ options = { :external_control => true,
63
+ :class => record.class.to_s,
64
+ :rows => 1,
65
+ :editing => true,
66
+ :on_complete => nil }.update(options || {})
67
+ rclass = options[:class]
68
+ outstr = <<-ENDDOC
69
+ <span id="#{jipe_id_for(record, field, options)}">
70
+ #{record.send(field).to_s}
71
+ </span>
71
72
  ENDDOC
73
+ if options[:editing]
74
+ outstr += <<-ENDDOC
75
+ #{ options[:external_control] ? image_tag("jipe/edit-field.png",
76
+ { :id => "edit_#{jipe_id_for(record, field, options)}" }) : "" }
77
+ #{ jipe_editor_for(record, field, options)}
78
+ ENDDOC
79
+ end
80
+ return outstr.html_safe
72
81
  end
73
- return outstr
74
- end
75
82
 
76
- def jipe_select_field(record, field, choices, options = {}, html_options = {})
77
- options = {
78
- :class => record.class.to_s,
79
- :on_complete => nil,
80
- }.update(options || {})
83
+ def jipe_select_field(record, field, choices, options = {}, html_options = {})
84
+ options = {
85
+ :class => record.class.to_s,
86
+ :on_complete => nil,
87
+ }.update(options || {})
81
88
 
82
- rclass = options.delete(:class)
83
- value = record.send(field)
84
- id = jipe_id_for(record, field, options)
89
+ rclass = options.delete(:class)
90
+ value = record.send(field)
91
+ id = jipe_id_for(record, field, options)
85
92
 
86
- js_options = {}
87
- js_options['onComplete'] = options.delete(:on_complete) if options[:on_complete]
88
- if protect_against_forgery?
89
- js_options["authenticityToken"] = form_authenticity_token
90
- end
91
- options.each do |k, v|
92
- if v.nil?
93
- options.delete(k)
94
- elsif v.kind_of? String
95
- options[k] = "'#{escape_javascript(v)}'"
93
+ js_options = {}
94
+ js_options['onComplete'] = options.delete(:on_complete) if options[:on_complete]
95
+ if protect_against_forgery?
96
+ js_options["authenticityToken"] = form_authenticity_token
96
97
  end
97
- end
98
- js_options['ajaxOptions'] = options_for_javascript(options)
98
+ options.each do |k, v|
99
+ if v.nil?
100
+ options.delete(k)
101
+ elsif v.kind_of? String
102
+ options[k] = "'#{escape_javascript(v)}'"
103
+ end
104
+ end
105
+ js_options['ajaxOptions'] = options_for_javascript(options)
99
106
 
100
- outstr = <<-ENDDOC
101
- #{select_tag id, options_for_select(choices, value), html_options}
102
- <script type="text/javascript">
103
- new Jipe.SelectField('#{id}', #{rclass}, #{record.id}, #{field.to_json},
104
- #{options_for_javascript js_options});
105
- </script>
106
- ENDDOC
107
- return outstr
108
- end
109
-
110
- def jipe_image_toggle(record, field, true_image, false_image, options = {})
111
- options = {
112
- :class => record.class.to_s,
113
- :on_complete => nil,
114
- }.update(options || {})
115
- rclass = options[:class]
116
- value = record.send(field)
117
- idprefix = jipe_id_for(record, field, options)
118
-
119
- js_options = {}
120
- js_options['onComplete'] = options[:on_complete] if options[:on_complete]
121
- if protect_against_forgery?
122
- js_options["authenticityToken"] = form_authenticity_token
123
- end
124
-
125
- outstr = <<-ENDDOC
126
- #{image_tag true_image, :id => "#{idprefix}_true",
127
- :style => (value ? "" : "display: none") }
128
- #{image_tag false_image, :id => "#{idprefix}_false",
129
- :style => (value ? "display: none" : "") }
107
+ outstr = <<-ENDDOC
108
+ #{select_tag id, options_for_select(choices, value), html_options}
130
109
  <script type="text/javascript">
131
- new Jipe.ImageToggle("#{idprefix}_true", "#{idprefix}_false",
132
- #{rclass}, #{record.id}, #{field.to_json},
110
+ new Jipe.SelectField('#{id}', #{rclass}, #{record.id}, #{field.to_json},
133
111
  #{options_for_javascript js_options});
134
112
  </script>
135
- ENDDOC
136
- return outstr
113
+ ENDDOC
114
+ return outstr.html_safe
115
+ end
116
+
117
+ def jipe_image_toggle(record, field, true_image, false_image, options = {})
118
+ options = {
119
+ :class => record.class.to_s,
120
+ :on_complete => nil,
121
+ }.update(options || {})
122
+ rclass = options[:class]
123
+ value = record.send(field)
124
+ idprefix = jipe_id_for(record, field, options)
125
+
126
+ js_options = {}
127
+ js_options['onComplete'] = options[:on_complete] if options[:on_complete]
128
+ if protect_against_forgery?
129
+ js_options["authenticityToken"] = form_authenticity_token
130
+ end
131
+
132
+ outstr = <<-ENDDOC
133
+ #{image_tag true_image, :id => "#{idprefix}_true",
134
+ :style => (value ? "" : "display: none") }
135
+ #{image_tag false_image, :id => "#{idprefix}_false",
136
+ :style => (value ? "display: none" : "") }
137
+ <script type="text/javascript">
138
+ new Jipe.ImageToggle("#{idprefix}_true", "#{idprefix}_false",
139
+ #{rclass}, #{record.id}, #{field.to_json},
140
+ #{options_for_javascript js_options});
141
+ </script>
142
+ ENDDOC
143
+ return outstr.html_safe
144
+ end
137
145
  end
138
146
  end