jipe 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,138 @@
1
+ # Jipe
2
+
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}"
13
+ end
14
+ 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}', "
36
+ end
37
+ outstr << "rows: #{options[:rows]},"
38
+ options.delete(:rows)
39
+ options.delete(:id)
40
+
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
49
+
50
+ outstr << "}});\n</script>"
51
+ return outstr
52
+ end
53
+
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)}
71
+ ENDDOC
72
+ end
73
+ return outstr
74
+ end
75
+
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 || {})
81
+
82
+ rclass = options.delete(:class)
83
+ value = record.send(field)
84
+ id = jipe_id_for(record, field, options)
85
+
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)}'"
96
+ end
97
+ end
98
+ js_options['ajaxOptions'] = options_for_javascript(options)
99
+
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" : "") }
130
+ <script type="text/javascript">
131
+ new Jipe.ImageToggle("#{idprefix}_true", "#{idprefix}_false",
132
+ #{rclass}, #{record.id}, #{field.to_json},
133
+ #{options_for_javascript js_options});
134
+ </script>
135
+ ENDDOC
136
+ return outstr
137
+ end
138
+ end
@@ -0,0 +1,2 @@
1
+ require 'jipe'
2
+ ActionView::Base.send :include, Jipe
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :jipe do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+
3
+ class JipeTest < Test::Unit::TestCase
4
+ # Replace this with your real tests.
5
+ def test_this_plugin
6
+ flunk
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jipe
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Nat Budin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-15 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :development
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 23
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ version: 1.0.0
35
+ name: bundler
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ type: :development
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 1
48
+ - 5
49
+ - 2
50
+ version: 1.5.2
51
+ name: jeweler
52
+ version_requirements: *id002
53
+ description:
54
+ email: natbudin@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - README
61
+ files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README
65
+ - Rakefile
66
+ - VERSION
67
+ - app/controllers/jipe_controller.rb
68
+ - app/views/jipe/jester.js.erb
69
+ - app/views/jipe/jipe.js.erb
70
+ - assets/images/edit-field.png
71
+ - assets/javascripts/jester.js
72
+ - assets/javascripts/jipe.js
73
+ - generators/jipe/USAGE
74
+ - generators/jipe/jipe_generator.rb
75
+ - generators/jipe/templates/edit-field.png
76
+ - init.rb
77
+ - install.rb
78
+ - jipe.gemspec
79
+ - lib/jipe.rb
80
+ - rails/init.rb
81
+ - tasks/jipe_tasks.rake
82
+ - test/jipe_test.rb
83
+ - uninstall.rb
84
+ has_rdoc: true
85
+ homepage: http://github.com/nbudin/jipe
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.5.0
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: RESTful In-place editors for Rails using Jester
118
+ test_files:
119
+ - test/jipe_test.rb