property_grid 0.0.1

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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in property_grid.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Marc Clifton
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,4 @@
1
+ property_grid
2
+ =============
3
+
4
+ A gem containing the classes and helper functions for the server-side Property Grid control. Also see the repository property_grid_demo for example usage.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,171 @@
1
+ require "property_grid/version"
2
+
3
+ module PropertyGrid
4
+ class PropertyGridTypes
5
+ def self.get_property_type_map
6
+ {
7
+ string: ControlType.new('text_field'),
8
+ text: ControlType.new('text_area'),
9
+ boolean: ControlType.new('check_box'),
10
+ password: ControlType.new('password_field'),
11
+ date: ControlType.new('datepicker'),
12
+ datetime: ControlType.new('text_field', 'jq_dateTimePicker'),
13
+ time: ControlType.new('text_field', 'jq_timePicker'),
14
+ color: ControlType.new('text_field', 'jq_colorPicker'),
15
+ list: ControlType.new('select'),
16
+ db_list: ControlType.new('select')
17
+ }
18
+ end
19
+ end
20
+
21
+ # A container mapping types to control classes
22
+ class ControlType
23
+ attr_accessor :type_name
24
+ attr_accessor :class_name
25
+
26
+ def initialize(type_name, class_name = nil)
27
+ @type_name = type_name
28
+ @class_name = class_name
29
+ end
30
+ end
31
+
32
+ # Defines a PropertyGrid group
33
+ # A group has a name and a collection of properties.
34
+ class PropertyGridGroup
35
+ attr_accessor :name
36
+ attr_accessor :properties
37
+
38
+ def initialize
39
+ @name = nil
40
+ @properties = []
41
+ end
42
+
43
+ # Adds a property to the properties collection and returns self.
44
+ def add_property(var, name, property_type = :string, collection = nil)
45
+ group_property = GroupProperty.new(var, name, property_type, collection)
46
+ @properties << group_property
47
+ self
48
+ end
49
+ end
50
+
51
+ # A container for a property within a group.
52
+ class GroupProperty
53
+ attr_accessor :property_var
54
+ attr_accessor :property_name
55
+ attr_accessor :property_type
56
+ attr_accessor :property_collection
57
+
58
+ # some of these use jquery: http://jqueryui.com/
59
+ def initialize(var, name, property_type, collection = nil)
60
+ @property_var = var
61
+ @property_name = name
62
+ @property_type = property_type
63
+ @property_collection = collection
64
+ end
65
+
66
+ # returns the ERB for this property as defined by its property_type
67
+ def get_input_control
68
+ form_type = PropertyGridTypes.get_property_type_map[@property_type]
69
+ raise "Property '#{@property_type}' is not mapped to an input control" if form_type.nil?
70
+ erb = get_erb(form_type)
71
+
72
+ erb
73
+ end
74
+
75
+ # Returns the erb for a given form type. This code handles the construction of the web control that will display
76
+ # the content of a property in the property grid.
77
+ # The web page must utilize a field_for ... |f| for this construction to work.
78
+ def get_erb(form_type)
79
+ erb = "<%= f.#{form_type.type_name} :#{@property_var}"
80
+ erb << ", class: '#{form_type.class_name}'" if form_type.class_name.present?
81
+ erb << ", #{@property_collection}" if @property_collection.present? && @property_type == :list
82
+ erb << ", options_from_collection_for_select(f.object.records, :id, :name, f.object.#{@property_var})" if @property_collection.present? && @property_type == :db_list
83
+ erb << "%>"
84
+
85
+ erb
86
+ end
87
+
88
+ end
89
+
90
+ # Class defining the property grid
91
+ # A property grid consists of property groups, and groups contain properties.
92
+ class APropertyGrid
93
+ attr_accessor :groups
94
+
95
+ def initialize
96
+ @groups = []
97
+ end
98
+
99
+ # Give a group name, creates a group, yielding to a block that can be used
100
+ # to define properties within the group, and returning self so that additional
101
+ # groups can be added in a fluid code style.
102
+ def add_group(name)
103
+ group = PropertyGridGroup.new
104
+ group.name = name
105
+ @groups << group
106
+ yield(group) # yields to block creating group properties
107
+ self # returns the PropertyGrid instance
108
+ end
109
+ end
110
+
111
+ # ********************************** DSL functions
112
+
113
+ def new_property_grid(name = nil)
114
+ @__property_grid = APropertyGrid.new
115
+
116
+ @__property_grid
117
+ end
118
+
119
+ def group(name)
120
+ group = PropertyGridGroup.new
121
+ group.name = name
122
+ @__property_grid.groups << group
123
+
124
+ group
125
+ end
126
+
127
+ def group_property(name, var, type = :string, collection = nil)
128
+ group_property = GroupProperty.new(var, name, type, collection)
129
+ @__property_grid.groups.last.properties << group_property
130
+
131
+ group_property
132
+ end
133
+
134
+ # ********************************** Helper functions
135
+
136
+ def generate_javascript_for_property_groups(grid)
137
+ javascript = ''
138
+
139
+ grid.groups.each_with_index do |grp, index|
140
+ javascript << get_javascript_for_group(index)
141
+ end
142
+
143
+ javascript
144
+ end
145
+
146
+ def get_javascript_for_group(index)
147
+ js = %Q|
148
+ $(".expandableGroup[idx]").click(function()
149
+ {
150
+ var hidden = $(".property_group[idx]").is(":hidden"); // get the value BEFORE making the slideToggle call.
151
+ $(".property_group[idx]").slideToggle('slow');
152
+
153
+ // At this point, $(".property_group0").is(":hidden");
154
+ // ALWAYS RETURNS FALSE
155
+
156
+ if (!hidden) // Remember, this is state that the div WAS in.
157
+ {
158
+ $(".expandableGroup[idx]").removeClass('expanded');
159
+ $(".expandableGroup[idx]").addClass('collapsed');
160
+ }
161
+ else
162
+ {
163
+ $(".expandableGroup[idx]").removeClass('collapsed');
164
+ $(".expandableGroup[idx]").addClass('expanded');
165
+ }
166
+ });
167
+ |.gsub('[idx]', index.to_s)
168
+
169
+ js
170
+ end
171
+ end
@@ -0,0 +1,3 @@
1
+ module PropertyGrid
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'property_grid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "property_grid"
8
+ spec.version = PropertyGrid::VERSION
9
+ spec.authors = ["Marc Clifton"]
10
+ spec.email = ["marc.clifton@gmail.com"]
11
+ spec.description = %q{A dynamic runtime property grid control.}
12
+ spec.summary = %q{A dynamic runtime property grid control.}
13
+ spec.homepage = "https://github.com/cliftonm/property_grid"
14
+ spec.license = "MIT"
15
+
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"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: property_grid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marc Clifton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &25523496 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *25523496
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &25522716 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *25522716
36
+ description: A dynamic runtime property grid control.
37
+ email:
38
+ - marc.clifton@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - lib/property_grid.rb
49
+ - lib/property_grid/version.rb
50
+ - property_grid.gemspec
51
+ homepage: https://github.com/cliftonm/property_grid
52
+ licenses:
53
+ - MIT
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.16
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: A dynamic runtime property grid control.
76
+ test_files: []