kematzy-dm-is-select 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -10,6 +10,7 @@ tmtags
10
10
  coverage
11
11
  rdoc
12
12
  pkg
13
+ doc
13
14
 
14
15
  ## PROJECT::SPECIFIC
15
16
 
File without changes
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.email = "kematzy@gmail.com"
12
12
  gem.homepage = "http://github.com/kematzy/dm-is-select"
13
13
  gem.authors = ["kematzy"]
14
- gem.extra_rdoc_files = %w[ README.rdoc LICENSE TODO History.txt ]
14
+ gem.extra_rdoc_files = %w[ README.rdoc LICENSE TODO History.rdoc ]
15
15
  gem.add_dependency('dm-core', '>= 0.10.0')
16
16
  gem.add_dependency('dm-more', '>= 0.10.0')
17
17
  # gem.add_dependency('dm-validations', '>= 0.10.0')
@@ -56,18 +56,42 @@ task :default => :spec
56
56
 
57
57
  require 'rake/rdoctask'
58
58
  Rake::RDocTask.new do |rdoc|
59
- if File.exist?('VERSION')
60
- version = IO.read('VERSION').chomp
61
- else
62
- version = "[Unknown]"
63
- end
64
-
59
+ version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
60
+
65
61
  rdoc.rdoc_dir = 'rdoc'
66
62
  rdoc.title = "dm-is-select #{version}"
67
63
  rdoc.rdoc_files.include('README*')
68
64
  rdoc.rdoc_files.include('lib/**/*.rb')
69
65
  end
70
66
 
67
+
68
+
69
+ desc 'Build the rdoc HTML Files'
70
+ task :docs do
71
+ version = File.exist?('VERSION') ? IO.read('VERSION').chomp : "[Unknown]"
72
+
73
+ sh "sdoc -N --title 'DM::Is::Select v#{version}' lib/dm-is-select README.rdoc"
74
+ end
75
+
76
+ namespace :docs do
77
+
78
+ desc 'Remove rdoc products'
79
+ task :remove => [:clobber_rdoc] do
80
+ sh "rm -rf doc"
81
+ end
82
+
83
+ desc 'Force a rebuild of the RDOC files'
84
+ task :rebuild => [:docs]
85
+
86
+ desc 'Build docs, and open in browser for viewing (specify BROWSER)'
87
+ task :open => [:docs] do
88
+ browser = ENV["BROWSER"] || "safari"
89
+ sh "open -a #{browser} doc/index.html"
90
+ end
91
+
92
+ end
93
+
94
+
71
95
  # kept just as a reference for now.
72
96
  #
73
97
  # def sudo_gem(cmd)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/dm-is-select.gemspec CHANGED
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{dm-is-select}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["kematzy"]
9
- s.date = %q{2009-07-15}
9
+ s.date = %q{2009-08-20}
10
10
  s.description = %q{A DataMapper plugin that makes getting the <tt><select></tt> options from a Model easier.}
11
11
  s.email = %q{kematzy@gmail.com}
12
12
  s.extra_rdoc_files = [
13
- "History.txt",
13
+ "History.rdoc",
14
14
  "LICENSE",
15
15
  "README.rdoc",
16
16
  "TODO"
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
- "History.txt",
20
+ "History.rdoc",
21
21
  "LICENSE",
22
22
  "README.rdoc",
23
23
  "Rakefile",
@@ -17,7 +17,7 @@ module DataMapper
17
17
  #
18
18
  # * :field_name => the name of the field values shown in select
19
19
  # * :options
20
- # * :is_tree => whether if the current Model is an is :tree model
20
+ # * :is_tree => whether if the current Model is an is :tree model. (Defaults to false)
21
21
  #
22
22
  # ==== Examples
23
23
  #
@@ -36,7 +36,7 @@ module DataMapper
36
36
 
37
37
  @select_options = {
38
38
  # add specical features if we are working with Tree Model
39
- :is_tree => false,
39
+ :is_tree => false
40
40
  }.merge(options)
41
41
 
42
42
  @select_field = select_field
@@ -80,6 +80,9 @@ module DataMapper
80
80
  # Category.items_for_select_menu(:order => [ :id.desc ] )
81
81
  # => array with the order reversed. (Prompts & divider always comes first)
82
82
  #
83
+ # Category.items_for_select_menu(:publish_status => "on", :order => [ :id.desc ] )
84
+ # => returns only those items that matches the query params or just an empty Select Menu
85
+ #
83
86
  # If your model is a Tree:
84
87
  #
85
88
  # Category.items_for_select_menu(:root_text => "Custom Root Text") # sets the text for the Top Level (root) Parent
@@ -89,18 +92,27 @@ module DataMapper
89
92
  #
90
93
  #
91
94
  # @api public
92
- def items_for_select_menu(options={})
95
+ def items_for_select_menu(options = {})
96
+ # clean out the various parts
97
+ html_options = options.only(:prompt, :divider, :show_root, :root_text)
98
+ sql_options = options.except(:prompt, :divider, :show_root, :root_text)
99
+ # puts "sql_options=[#{sql_options.inspect}] [#{__FILE__}:#{__LINE__}]"
100
+ # puts "html_options=[#{html_options.inspect}] [#{__FILE__}:#{__LINE__}]"
101
+
93
102
  options = {
94
103
  :prompt => "Select #{self.name}",
95
104
  :divider => true,
96
- :order => [self.select_field.to_sym],
97
105
  :show_root => true,
98
106
  :root_text => "Top Level #{self.name}",
99
- }.merge(options)
107
+ }.merge(html_options)
108
+
109
+ sql_options = {
110
+ :order => [self.select_field.to_sym],
111
+ }.merge(sql_options)
100
112
 
101
113
  mi = self.select_options[:is_tree] ?
102
- all(:parent_id => 0, :order => options[:order] ) :
103
- all(:order => options[:order])
114
+ all({ :parent_id => 0 }.merge(sql_options) ) :
115
+ all(sql_options)
104
116
 
105
117
  res = []
106
118
  if options[:prompt]
@@ -1,7 +1,7 @@
1
1
  module DataMapper
2
2
  module Is
3
3
  module Select
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
7
7
  end
@@ -8,6 +8,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
8
8
  include DataMapper::Resource
9
9
  property :id, Serial
10
10
  property :name, String
11
+ property :publish_status, String, :default => "on"
11
12
 
12
13
  is :select, :name
13
14
 
@@ -18,6 +19,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
18
19
  include DataMapper::Resource
19
20
  property :id, Serial
20
21
  property :name, String
22
+ property :publish_status, String, :default => "on"
21
23
 
22
24
  is :tree, :order => :name
23
25
  is :select, :name, :is_tree => true
@@ -25,7 +27,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
25
27
  auto_migrate!
26
28
  end
27
29
 
28
-
29
30
  5.times do |n|
30
31
  Category.create(:name => "Category #{n+1}")
31
32
  end
@@ -146,6 +147,33 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
146
147
  ]
147
148
  end
148
149
 
150
+ it "should respect the SQL select options" do
151
+ c = Category.get(1)
152
+ c.publish_status = 'off'
153
+ c.save
154
+
155
+ Category.items_for_select_menu(:publish_status => "on", :order => [ :id.desc ] ).should == [
156
+ ["Select Category", nil],
157
+ [" ------ ", "nil"],
158
+ ["Category 5", 5],
159
+ ["Category 4", 4],
160
+ ["Category 3", 3],
161
+ ["Category 2", 2],
162
+ # ["Category 1", 1]
163
+ ]
164
+ end
165
+ it "should handle invalid SQL select options" do
166
+ Category.items_for_select_menu(:publish_status => "invalid", :order => [ :id.desc ] ).should == [
167
+ ["Select Category", nil],
168
+ [" ------ ", "nil"],
169
+ # ["Category 5", 5],
170
+ # ["Category 4", 4],
171
+ # ["Category 3", 3],
172
+ # ["Category 2", 2],
173
+ # ["Category 1", 1]
174
+ ]
175
+ end
176
+
149
177
  end #/ Normal Model
150
178
 
151
179
  describe "Tree Model" do
@@ -208,6 +236,40 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
208
236
  ]
209
237
  end
210
238
 
239
+ it "should respect the SQL select options" do
240
+ c = TreeCategory.get(1)
241
+ c.publish_status = 'off'
242
+ c.save
243
+
244
+ TreeCategory.items_for_select_menu( :publish_status => "on", :order => [ :id.desc ] ).should == [
245
+ ["Select TreeCategory", nil],
246
+ [" ------ ", "nil"],
247
+ ["Top Level TreeCategory", 0],
248
+ [" ------ ", "nil"],
249
+ ["TreeCategory-2", 4],
250
+ ["-- TreeCategory-2-Child", 5],
251
+ ["-- -- TreeCategory-2-Child-GrandChild", 6],
252
+ # ["TreeCategory-1", 1],
253
+ # ["-- TreeCategory-1-Child", 2],
254
+ # ["-- -- TreeCategory-1-Child-GrandChild", 3]
255
+ ]
256
+ end
257
+
258
+ it "should handle invalid SQL select options" do
259
+ TreeCategory.items_for_select_menu( :publish_status => "invalid", :order => [ :id.desc ] ).should == [
260
+ ["Select TreeCategory", nil],
261
+ [" ------ ", "nil"],
262
+ ["Top Level TreeCategory", 0],
263
+ [" ------ ", "nil"],
264
+ # ["TreeCategory-2", 4],
265
+ # ["-- TreeCategory-2-Child", 5],
266
+ # ["-- -- TreeCategory-2-Child-GrandChild", 6],
267
+ # ["TreeCategory-1", 1],
268
+ # ["-- TreeCategory-1-Child", 2],
269
+ # ["-- -- TreeCategory-1-Child-GrandChild", 3]
270
+ ]
271
+ end
272
+
211
273
  end #/ Tree Model
212
274
 
213
275
  end #/ #item_for_select_menu
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kematzy-dm-is-select
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kematzy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-15 00:00:00 -07:00
12
+ date: 2009-08-20 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,13 +39,13 @@ executables: []
39
39
  extensions: []
40
40
 
41
41
  extra_rdoc_files:
42
- - History.txt
42
+ - History.rdoc
43
43
  - LICENSE
44
44
  - README.rdoc
45
45
  - TODO
46
46
  files:
47
47
  - .gitignore
48
- - History.txt
48
+ - History.rdoc
49
49
  - LICENSE
50
50
  - README.rdoc
51
51
  - Rakefile
@@ -60,6 +60,7 @@ files:
60
60
  - spec/spec_helper.rb
61
61
  has_rdoc: false
62
62
  homepage: http://github.com/kematzy/dm-is-select
63
+ licenses:
63
64
  post_install_message:
64
65
  rdoc_options:
65
66
  - --charset=UTF-8
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  requirements: []
81
82
 
82
83
  rubyforge_project:
83
- rubygems_version: 1.2.0
84
+ rubygems_version: 1.3.5
84
85
  signing_key:
85
86
  specification_version: 3
86
87
  summary: A DataMapper plugin that makes getting the <tt><select></tt> options from a Model easier.