inspector_dragit 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = InspectorDragit
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'InspectorDragit'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,50 @@
1
+ function replace_element_w_i_d_draggable_info(ele, draggable) {
2
+ var insp_d_data = $.parseJSON(draggable.attr("data-inspector-dragit"));
3
+ var content = "<table>";
4
+ for (var i = 0; i < insp_d_data.attributes.length; i++) {
5
+ var label = insp_d_data.attributes[i].label
6
+ var value = insp_d_data.attributes[i].value
7
+ content += '<tr><td>' + label + ': </td><td>' + value + '</td></tr>';
8
+ }
9
+ content += "</table>"
10
+ $(ele).html(content);
11
+ }
12
+
13
+ (function( $ ){
14
+ var methods = {
15
+ init: function(options) {
16
+ $(".inspector_dragit_inspector", $(this)).each(function(){
17
+ $(this).droppable({
18
+ accept: ".inspector_dragit_draggable",
19
+ activeClass: "drop-focus",
20
+ drop: function( event, ui ) {
21
+ //TODO: the function below might be better off living inside
22
+ replace_element_w_i_d_draggable_info(this, ui.draggable);
23
+ }
24
+ });
25
+ });
26
+
27
+ $(".inspector_dragit_draggable", $(this)).each(function(){
28
+ $( $(this) ).draggable({
29
+ revert: "invalid",
30
+ containment: "document",
31
+ helper: "clone",
32
+ cursor: "move"
33
+ })
34
+ });
35
+ }
36
+ };
37
+
38
+ jQuery.fn.inspector_dragit = function(method) {
39
+ if ( methods[method] ) {
40
+ if(method !== 'init') {methods.init.apply( this, arguments );}
41
+ methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
42
+ return methods;
43
+ } else if ( typeof method === 'object' || ! method ) {
44
+ methods.init.apply( this, arguments );
45
+ return methods;
46
+ } else {
47
+ $.error( 'Method ' + method + ' does not exist on jQuery.marking' );
48
+ }
49
+ };
50
+ })( jQuery );
@@ -0,0 +1,7 @@
1
+ require 'inspector_dragit/wowzers'
2
+ require 'inspector_dragit/view_helpers'
3
+ require 'inspector_dragit/active_record'
4
+ require "inspector_dragit/engine"
5
+
6
+ module InspectorDragit
7
+ end
@@ -0,0 +1,41 @@
1
+ module InspectorDragit
2
+ module ActiveRecord
3
+ class AttributeBuilder < Array
4
+ def add(label, attr)
5
+ self << {:label => label,:attr => attr}
6
+ end
7
+ end
8
+
9
+ module Include
10
+ def inspector_dragit_template
11
+ self.class.respond_to?(:class_insp_dragit_template) ? self.class.class_insp_dragit_template : {:title => "", :attributes => []}
12
+ end
13
+
14
+ def inspector_dragit_data
15
+ id_data = {}
16
+ id_data[:title] = inspector_dragit_template[:title]
17
+ id_data[:attributes] = []
18
+ inspector_dragit_template[:attributes].each do |a_hash|
19
+ id_data[:attributes] << {:label => a_hash[:label], :value => self.send(a_hash[:attr]) }
20
+ end
21
+ id_data
22
+ end
23
+ end
24
+
25
+ module Extend
26
+ attr_accessor :class_insp_dragit_template, :class_insp_dragit_title, :class_insp_dragit_attrs
27
+
28
+ @class_insp_dragit_title = ""
29
+ @class_insp_dragit_attrs = AttributeBuilder.new
30
+ @class_insp_dragit_template = {:title => @class_insp_dragit_title, :attributes => @class_insp_dragit_attrs}
31
+
32
+ def go_go_dragit(&block)
33
+ @class_insp_dragit_title = ""
34
+ @class_insp_dragit_attrs = AttributeBuilder.new
35
+ block.call(@class_insp_dragit_title, @class_insp_dragit_attrs)
36
+ @class_insp_dragit_template = {:title => @class_insp_dragit_title,
37
+ :attributes => @class_insp_dragit_attrs}
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,18 @@
1
+ module InspectorDragit
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace InspectorDragit
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.integration_tool :rspec
8
+ end
9
+
10
+ initializer "inspector_dragit.view_helpers" do |app|
11
+ ::ActionView::Base.send :include, ::InspectorDragit::ViewHelpers
12
+ end
13
+
14
+ initializer "inspector_dragit.active_record" do |app|
15
+ ::ActiveRecord::Base.send :include, ::InspectorDragit::ActiveRecord::Include
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module InspectorDragit
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,36 @@
1
+ module InspectorDragit
2
+ module ViewHelpers
3
+ def isp_dragit_draggable_class
4
+ "inspector_dragit_draggable"
5
+ end
6
+
7
+ def isp_dragit_inspector_class
8
+ "inspector_dragit_inspector"
9
+ end
10
+
11
+ def go_go_dragit_draggable_content(name, record, content_or_options_with_block = nil, opts = nil, escape = true, &block)
12
+ opts = {} if opts.nil?
13
+ opts[:data] = {} if opts[:data].nil?
14
+ opts[:data][:inspector_dragit] = record.inspector_dragit_data.to_json
15
+
16
+ if opts[:class].blank?
17
+ opts[:class] = isp_dragit_draggable_class
18
+ else
19
+ opts[:class] << " " << isp_dragit_draggable_class
20
+ end
21
+
22
+ content_tag(name, content_or_options_with_block, opts, escape, &block)
23
+ end
24
+
25
+ def go_go_dragit_inspector_content(name=:div, content_or_options_with_block = nil, opts = nil, escape = true, &block)
26
+ opts = {} if opts.nil?
27
+ if opts[:class].blank?
28
+ opts[:class] = isp_dragit_inspector_class
29
+ else
30
+ opts[:class] << " " << isp_dragit_inspector_class
31
+ end
32
+
33
+ return content_tag(name, content_or_options_with_block, opts, escape, &block)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ module InspectorDragit
2
+ module Wowzers
3
+ class InvalidRecordArgument < Exception
4
+ def message
5
+ "Wowzer: Please make sure you pass ActiveRecords that include the InspectorDragit::ActiveRecord module."
6
+ end
7
+ end
8
+
9
+ class InvalidInspectorArgument < Exception
10
+ def message
11
+ "Wowzer: The inspector view helper is being passed the correct options."
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :inspector_dragit do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspector_dragit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher William Parratto Jr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: haml
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: haml-rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jquery-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jquery-ui-themes
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: spork
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-spork
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Drag and drop attribute inspector. Nests model attributes as html 5 data
143
+ attributes on any html element. The element becomes a draggable element. Drag elements
144
+ to an inspector div to view its properties.
145
+ email:
146
+ - cparratto@gmail.com
147
+ executables: []
148
+ extensions: []
149
+ extra_rdoc_files: []
150
+ files:
151
+ - app/assets/javascripts/inspector_dragit.js
152
+ - lib/inspector_dragit.rb
153
+ - lib/inspector_dragit/version.rb
154
+ - lib/inspector_dragit/wowzers.rb
155
+ - lib/inspector_dragit/active_record.rb
156
+ - lib/inspector_dragit/view_helpers.rb
157
+ - lib/inspector_dragit/engine.rb
158
+ - lib/tasks/inspector_dragit_tasks.rake
159
+ - MIT-LICENSE
160
+ - Rakefile
161
+ - README.rdoc
162
+ homepage: https://github.com/cparratto/Inspector-Dragit
163
+ licenses: []
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 1.8.24
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: Drag an drop attribute inspector.
186
+ test_files: []
187
+ has_rdoc: