merb-admin 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitignore +29 -27
  2. data/Gemfile +24 -22
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +20 -20
  5. data/README.rdoc +54 -58
  6. data/Rakefile +11 -44
  7. data/app/controllers/application.rb +6 -6
  8. data/app/controllers/main.rb +191 -191
  9. data/app/helpers/application_helper.rb +64 -64
  10. data/app/helpers/main_helper.rb +167 -167
  11. data/app/models/.gitkeep +0 -0
  12. data/app/views/layout/_message.html.erb +10 -10
  13. data/app/views/layout/dashboard.html.erb +34 -34
  14. data/app/views/layout/form.html.erb +48 -48
  15. data/app/views/layout/list.html.erb +42 -42
  16. data/app/views/main/_belongs_to.html.erb +29 -29
  17. data/app/views/main/_big_decimal.html.erb +12 -12
  18. data/app/views/main/_boolean.html.erb +7 -7
  19. data/app/views/main/_date.html.erb +12 -12
  20. data/app/views/main/_datetime.html.erb +12 -12
  21. data/app/views/main/_float.html.erb +12 -12
  22. data/app/views/main/_has_many.html.erb +16 -16
  23. data/app/views/main/_has_one.html.erb +30 -30
  24. data/app/views/main/_integer.html.erb +12 -12
  25. data/app/views/main/_properties.html.erb +18 -18
  26. data/app/views/main/_string.html.erb +15 -15
  27. data/app/views/main/_text.html.erb +11 -11
  28. data/app/views/main/_time.html.erb +12 -12
  29. data/app/views/main/_timestamp.html.erb +12 -12
  30. data/app/views/main/delete.html.erb +28 -28
  31. data/app/views/main/edit.html.erb +19 -19
  32. data/app/views/main/index.html.erb +22 -22
  33. data/app/views/main/list.html.erb +93 -93
  34. data/app/views/main/new.html.erb +16 -16
  35. data/config/init.rb +30 -0
  36. data/config/router.rb +4 -0
  37. data/lib/abstract_model.rb +84 -86
  38. data/lib/active_record_support.rb +147 -147
  39. data/lib/datamapper_support.rb +139 -140
  40. data/lib/generic_support.rb +13 -13
  41. data/lib/merb-admin.rb +99 -99
  42. data/lib/merb-admin/merbtasks.rb +103 -103
  43. data/lib/merb-admin/slicetasks.rb +174 -174
  44. data/lib/merb-admin/spectasks.rb +55 -55
  45. data/lib/merb-admin/version.rb +3 -0
  46. data/lib/sequel_support.rb +275 -275
  47. data/merb-admin.gemspec +42 -232
  48. data/public/javascripts/CollapsedFieldsets.js +85 -85
  49. data/public/javascripts/DateTimeShortcuts.js +255 -255
  50. data/public/javascripts/RelatedObjectLookups.js +96 -96
  51. data/public/javascripts/SelectBox.js +111 -111
  52. data/public/javascripts/SelectFilter2.js +113 -113
  53. data/public/javascripts/actions.js +39 -39
  54. data/public/javascripts/calendar.js +143 -143
  55. data/public/javascripts/core.js +176 -176
  56. data/public/javascripts/dateparse.js +233 -233
  57. data/public/javascripts/getElementsBySelector.js +167 -167
  58. data/public/javascripts/i18n.js +33 -33
  59. data/public/javascripts/ordering.js +137 -137
  60. data/public/javascripts/timeparse.js +94 -94
  61. data/public/javascripts/urlify.js +140 -140
  62. data/public/stylesheets/base.css +746 -746
  63. data/public/stylesheets/changelists.css +269 -269
  64. data/public/stylesheets/dashboard.css +24 -24
  65. data/public/stylesheets/forms.css +327 -327
  66. data/public/stylesheets/global.css +142 -142
  67. data/public/stylesheets/ie.css +50 -50
  68. data/public/stylesheets/layout.css +29 -29
  69. data/public/stylesheets/login.css +54 -54
  70. data/public/stylesheets/master.css +1 -1
  71. data/public/stylesheets/patch-iewin.css +7 -7
  72. data/public/stylesheets/rtl.css +206 -206
  73. data/public/stylesheets/widgets.css +506 -506
  74. data/screenshots/create.png +0 -0
  75. data/screenshots/delete.png +0 -0
  76. data/screenshots/edit.png +0 -0
  77. data/screenshots/index.png +0 -0
  78. data/screenshots/list.png +0 -0
  79. data/screenshots/new.png +0 -0
  80. data/spec/controllers/main_spec.rb +25 -25
  81. data/spec/migrations/activerecord/001_create_divisions_migration.rb +13 -13
  82. data/spec/migrations/activerecord/002_create_drafts_migration.rb +19 -19
  83. data/spec/migrations/activerecord/003_create_leagues_migration.rb +12 -12
  84. data/spec/migrations/activerecord/004_create_players_migration.rb +19 -20
  85. data/spec/migrations/activerecord/005_create_teams_migration.rb +22 -22
  86. data/spec/migrations/sequel/001_create_divisions_migration.rb +15 -15
  87. data/spec/migrations/sequel/002_create_drafts_migration.rb +21 -21
  88. data/spec/migrations/sequel/003_create_leagues_migration.rb +14 -14
  89. data/spec/migrations/sequel/004_create_players_migration.rb +21 -22
  90. data/spec/migrations/sequel/005_create_teams_migration.rb +24 -24
  91. data/spec/models/activerecord/division.rb +7 -7
  92. data/spec/models/activerecord/draft.rb +11 -11
  93. data/spec/models/activerecord/league.rb +6 -6
  94. data/spec/models/activerecord/player.rb +8 -8
  95. data/spec/models/activerecord/team.rb +13 -13
  96. data/spec/models/datamapper/division.rb +12 -12
  97. data/spec/models/datamapper/draft.rb +18 -18
  98. data/spec/models/datamapper/league.rb +11 -11
  99. data/spec/models/datamapper/player.rb +20 -21
  100. data/spec/models/datamapper/team.rb +22 -22
  101. data/spec/models/sequel/division.rb +15 -15
  102. data/spec/models/sequel/draft.rb +19 -19
  103. data/spec/models/sequel/league.rb +14 -14
  104. data/spec/models/sequel/player.rb +18 -18
  105. data/spec/models/sequel/team.rb +21 -21
  106. data/spec/requests/main_spec.rb +763 -763
  107. data/spec/spec_helper.rb +113 -112
  108. metadata +247 -41
  109. data/VERSION +0 -1
@@ -1,64 +1,64 @@
1
- module Merb
2
- module MerbAdmin
3
- module ApplicationHelper
4
-
5
- # @param *segments<Array[#to_s]> Path segments to append.
6
- #
7
- # @return <String>
8
- # A path relative to the public directory, with added segments.
9
- def image_path(*segments)
10
- public_path_for(:image, *segments)
11
- end
12
-
13
- # @param *segments<Array[#to_s]> Path segments to append.
14
- #
15
- # @return <String>
16
- # A path relative to the public directory, with added segments.
17
- def javascript_path(*segments)
18
- public_path_for(:javascript, *segments)
19
- end
20
-
21
- # @param *segments<Array[#to_s]> Path segments to append.
22
- #
23
- # @return <String>
24
- # A path relative to the public directory, with added segments.
25
- def stylesheet_path(*segments)
26
- public_path_for(:stylesheet, *segments)
27
- end
28
-
29
- # Construct a path relative to the public directory
30
- #
31
- # @param <Symbol> The type of component.
32
- # @param *segments<Array[#to_s]> Path segments to append.
33
- #
34
- # @return <String>
35
- # A path relative to the public directory, with added segments.
36
- def public_path_for(type, *segments)
37
- ::MerbAdmin.public_path_for(type, *segments)
38
- end
39
-
40
- # Construct an app-level path.
41
- #
42
- # @param <Symbol> The type of component.
43
- # @param *segments<Array[#to_s]> Path segments to append.
44
- #
45
- # @return <String>
46
- # A path within the host application, with added segments.
47
- def app_path_for(type, *segments)
48
- ::MerbAdmin.app_path_for(type, *segments)
49
- end
50
-
51
- # Construct a slice-level path.
52
- #
53
- # @param <Symbol> The type of component.
54
- # @param *segments<Array[#to_s]> Path segments to append.
55
- #
56
- # @return <String>
57
- # A path within the slice source (Gem), with added segments.
58
- def slice_path_for(type, *segments)
59
- ::MerbAdmin.slice_path_for(type, *segments)
60
- end
61
-
62
- end
63
- end
64
- end
1
+ module Merb
2
+ module MerbAdmin
3
+ module ApplicationHelper
4
+
5
+ # @param *segments<Array[#to_s]> Path segments to append.
6
+ #
7
+ # @return <String>
8
+ # A path relative to the public directory, with added segments.
9
+ def image_path(*segments)
10
+ public_path_for(:image, *segments)
11
+ end
12
+
13
+ # @param *segments<Array[#to_s]> Path segments to append.
14
+ #
15
+ # @return <String>
16
+ # A path relative to the public directory, with added segments.
17
+ def javascript_path(*segments)
18
+ public_path_for(:javascript, *segments)
19
+ end
20
+
21
+ # @param *segments<Array[#to_s]> Path segments to append.
22
+ #
23
+ # @return <String>
24
+ # A path relative to the public directory, with added segments.
25
+ def stylesheet_path(*segments)
26
+ public_path_for(:stylesheet, *segments)
27
+ end
28
+
29
+ # Construct a path relative to the public directory
30
+ #
31
+ # @param <Symbol> The type of component.
32
+ # @param *segments<Array[#to_s]> Path segments to append.
33
+ #
34
+ # @return <String>
35
+ # A path relative to the public directory, with added segments.
36
+ def public_path_for(type, *segments)
37
+ ::MerbAdmin.public_path_for(type, *segments)
38
+ end
39
+
40
+ # Construct an app-level path.
41
+ #
42
+ # @param <Symbol> The type of component.
43
+ # @param *segments<Array[#to_s]> Path segments to append.
44
+ #
45
+ # @return <String>
46
+ # A path within the host application, with added segments.
47
+ def app_path_for(type, *segments)
48
+ ::MerbAdmin.app_path_for(type, *segments)
49
+ end
50
+
51
+ # Construct a slice-level path.
52
+ #
53
+ # @param <Symbol> The type of component.
54
+ # @param *segments<Array[#to_s]> Path segments to append.
55
+ #
56
+ # @return <String>
57
+ # A path within the slice source (Gem), with added segments.
58
+ def slice_path_for(type, *segments)
59
+ ::MerbAdmin.slice_path_for(type, *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -1,167 +1,167 @@
1
- require 'builder'
2
- module Merb
3
- module MerbAdmin
4
- module MainHelper
5
- def to_model_name(param)
6
- param.split("::").map{|x| x.camel_case}.join("::")
7
- end
8
-
9
- def object_label(object)
10
- if object.nil?
11
- nil
12
- elsif object.respond_to?(:name) && object.name
13
- object.name
14
- elsif object.respond_to?(:title) && object.title
15
- object.title
16
- else
17
- "#{object.class.to_s} ##{object.id}"
18
- end
19
- end
20
-
21
- def object_property(object, property)
22
- property_type = property[:type]
23
- property_name = property[:name]
24
- case property_type
25
- when :boolean
26
- if object.send(property_name) == true
27
- Builder::XmlMarkup.new.img(:src => image_path("icon-yes.gif"), :alt => "True")
28
- else
29
- Builder::XmlMarkup.new.img(:src => image_path("icon-no.gif"), :alt => "False")
30
- end
31
- when :datetime
32
- value = object.send(property_name)
33
- value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y, %I:%M%p") : nil
34
- when :date
35
- value = object.send(property_name)
36
- value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y") : nil
37
- when :time
38
- value = object.send(property_name)
39
- value.respond_to?(:strftime) ? value.strftime("%I:%M%p") : nil
40
- when :string
41
- if property_name.to_s =~ /(image|logo|photo|photograph|picture|thumb|thumbnail)_ur(i|l)/i
42
- Builder::XmlMarkup.new.img(:src => object.send(property_name), :width => 10, :height => 10)
43
- else
44
- object.send(property_name).to_s.truncate(50)
45
- end
46
- when :text
47
- object.send(property_name).to_s.truncate(50)
48
- when :integer
49
- association = @abstract_model.belongs_to_associations.select{|a| a[:child_key].first == property_name}.first
50
- if association
51
- object_label(object.send(association[:name]))
52
- else
53
- object.send(property_name)
54
- end
55
- else
56
- object.send(property_name)
57
- end
58
- end
59
-
60
- # Given a page count and the current page, we generate a set of pagination
61
- # links.
62
- #
63
- # * We use an inner and outer window into a list of links. For a set of
64
- # 20 pages with the current page being 10:
65
- # outer_window:
66
- # 1 2 ..... 19 20
67
- # inner_window
68
- # 5 6 7 8 9 10 11 12 13 14
69
- #
70
- # This is totally adjustable, or can be turned off by giving the
71
- # :inner_window setting a value of nil.
72
- #
73
- # * Options
74
- # :left_cut_label => <em>text_for_cut</em>::
75
- # Used when the page numbers need to be cut off to prevent the set of
76
- # pagination links from being too long.
77
- # Defaults to '&hellip;'
78
- # :right_cut_label => <em>text_for_cut</em>::
79
- # Same as :left_cut_label but for the right side of numbers.
80
- # Defaults to '&hellip;'
81
- # :outer_window => <em>number_of_pages</em>::
82
- # Sets the number of pages to include in the outer 'window'
83
- # Defaults to 2
84
- # :inner_window => <em>number_of_pages</em>::
85
- # Sets the number of pags to include in the inner 'window'
86
- # Defaults to 7
87
- # :page_param => <em>name_of_page_paramiter</em>
88
- # Sets the name of the paramiter the paginator uses to return what
89
- # page is being requested.
90
- # Defaults to 'page'
91
- # :url => <em>url_for_links</em>
92
- # Provides the base url to use in the page navigation links.
93
- # Defaults to ''
94
- def paginate(current_page, page_count, options = {})
95
- options[:left_cut_label] ||= '&hellip;'
96
- options[:right_cut_label] ||= '&hellip;'
97
- options[:outer_window] ||= 2
98
- options[:inner_window] ||= 7
99
- options[:page_param] ||= 'page'
100
- options[:url] ||= ''
101
-
102
- url = options.delete(:url)
103
- url << (url.include?('?') ? '&' : '?') << options[:page_param]
104
-
105
- pages = {
106
- :all => (1..page_count).to_a,
107
- :left => [],
108
- :center => [],
109
- :right => []
110
- }
111
-
112
- # Only worry about using our 'windows' if the page count is less then
113
- # our windows combined.
114
- if options[:inner_window].nil? || ((options[:outer_window] * 2) + options[:inner_window] + 2) >= page_count
115
- pages[:center] = pages[:all]
116
- else
117
- pages[:left] = pages[:all][0, options[:outer_window]]
118
- pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
119
- pages[:center] = case current_page
120
- # allow the inner 'window' to shift to right when close to the left edge
121
- # Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
122
- when -infinity .. (options[:inner_window] / 2) + 3
123
- pages[:all][options[:outer_window], options[:inner_window]] +
124
- [options[:right_cut_label]]
125
- # allow the inner 'window' to shift left when close to the right edge
126
- # Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
127
- when (page_count - (options[:inner_window] / 2.0).ceil) - 1 .. infinity
128
- [options[:left_cut_label]] +
129
- pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
130
- # Display the unshifed window
131
- # ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
132
- else
133
- [options[:left_cut_label]] +
134
- pages[:all][current_page - (options[:inner_window] / 2) - 1, options[:inner_window]] +
135
- [options[:right_cut_label]]
136
- end
137
- end
138
-
139
- b = []
140
-
141
- [pages[:left], pages[:center], pages[:right]].each do |p|
142
- p.each do |page_number|
143
- case page_number
144
- when String
145
- b << page_number
146
- when current_page
147
- b << Builder::XmlMarkup.new.span(page_number, :class => "this-page")
148
- when page_count
149
- b << Builder::XmlMarkup.new.a(page_number, :class => "end", :href => "#{url}=#{page_number}")
150
- else
151
- b << Builder::XmlMarkup.new.a(page_number, :href => "#{url}=#{page_number}")
152
- end
153
- end
154
- end
155
-
156
- b.join(" ")
157
- end
158
-
159
- private
160
-
161
- def infinity
162
- 1.0 / 0
163
- end
164
-
165
- end
166
- end
167
- end
1
+ require 'builder'
2
+ module Merb
3
+ module MerbAdmin
4
+ module MainHelper
5
+ def to_model_name(param)
6
+ param.split("::").map{|x| x.camel_case}.join("::")
7
+ end
8
+
9
+ def object_label(object)
10
+ if object.nil?
11
+ nil
12
+ elsif object.respond_to?(:name) && object.name
13
+ object.name
14
+ elsif object.respond_to?(:title) && object.title
15
+ object.title
16
+ else
17
+ "#{object.class.to_s} ##{object.id}"
18
+ end
19
+ end
20
+
21
+ def object_property(object, property)
22
+ property_type = property[:type]
23
+ property_name = property[:name]
24
+ case property_type
25
+ when :boolean
26
+ if object.send(property_name) == true
27
+ Builder::XmlMarkup.new.img(:src => image_path("icon-yes.gif"), :alt => "True")
28
+ else
29
+ Builder::XmlMarkup.new.img(:src => image_path("icon-no.gif"), :alt => "False")
30
+ end
31
+ when :datetime
32
+ value = object.send(property_name)
33
+ value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y, %I:%M%p") : nil
34
+ when :date
35
+ value = object.send(property_name)
36
+ value.respond_to?(:strftime) ? value.strftime("%b. %d, %Y") : nil
37
+ when :time
38
+ value = object.send(property_name)
39
+ value.respond_to?(:strftime) ? value.strftime("%I:%M%p") : nil
40
+ when :string
41
+ if property_name.to_s =~ /(image|logo|photo|photograph|picture|thumb|thumbnail)_ur(i|l)/i
42
+ Builder::XmlMarkup.new.img(:src => object.send(property_name), :width => 10, :height => 10)
43
+ else
44
+ object.send(property_name).to_s.truncate(50)
45
+ end
46
+ when :text
47
+ object.send(property_name).to_s.truncate(50)
48
+ when :integer
49
+ association = @abstract_model.belongs_to_associations.select{|a| a[:child_key].first == property_name}.first
50
+ if association
51
+ object_label(object.send(association[:name]))
52
+ else
53
+ object.send(property_name)
54
+ end
55
+ else
56
+ object.send(property_name)
57
+ end
58
+ end
59
+
60
+ # Given a page count and the current page, we generate a set of pagination
61
+ # links.
62
+ #
63
+ # * We use an inner and outer window into a list of links. For a set of
64
+ # 20 pages with the current page being 10:
65
+ # outer_window:
66
+ # 1 2 ..... 19 20
67
+ # inner_window
68
+ # 5 6 7 8 9 10 11 12 13 14
69
+ #
70
+ # This is totally adjustable, or can be turned off by giving the
71
+ # :inner_window setting a value of nil.
72
+ #
73
+ # * Options
74
+ # :left_cut_label => <em>text_for_cut</em>::
75
+ # Used when the page numbers need to be cut off to prevent the set of
76
+ # pagination links from being too long.
77
+ # Defaults to '&hellip;'
78
+ # :right_cut_label => <em>text_for_cut</em>::
79
+ # Same as :left_cut_label but for the right side of numbers.
80
+ # Defaults to '&hellip;'
81
+ # :outer_window => <em>number_of_pages</em>::
82
+ # Sets the number of pages to include in the outer 'window'
83
+ # Defaults to 2
84
+ # :inner_window => <em>number_of_pages</em>::
85
+ # Sets the number of pags to include in the inner 'window'
86
+ # Defaults to 7
87
+ # :page_param => <em>name_of_page_paramiter</em>
88
+ # Sets the name of the paramiter the paginator uses to return what
89
+ # page is being requested.
90
+ # Defaults to 'page'
91
+ # :url => <em>url_for_links</em>
92
+ # Provides the base url to use in the page navigation links.
93
+ # Defaults to ''
94
+ def paginate(current_page, page_count, options = {})
95
+ options[:left_cut_label] ||= '&hellip;'
96
+ options[:right_cut_label] ||= '&hellip;'
97
+ options[:outer_window] ||= 2
98
+ options[:inner_window] ||= 7
99
+ options[:page_param] ||= 'page'
100
+ options[:url] ||= ''
101
+
102
+ url = options.delete(:url)
103
+ url << (url.include?('?') ? '&' : '?') << options[:page_param]
104
+
105
+ pages = {
106
+ :all => (1..page_count).to_a,
107
+ :left => [],
108
+ :center => [],
109
+ :right => []
110
+ }
111
+
112
+ # Only worry about using our 'windows' if the page count is less then
113
+ # our windows combined.
114
+ if options[:inner_window].nil? || ((options[:outer_window] * 2) + options[:inner_window] + 2) >= page_count
115
+ pages[:center] = pages[:all]
116
+ else
117
+ pages[:left] = pages[:all][0, options[:outer_window]]
118
+ pages[:right] = pages[:all][page_count - options[:outer_window], options[:outer_window]]
119
+ pages[:center] = case current_page
120
+ # allow the inner 'window' to shift to right when close to the left edge
121
+ # Ex: 1 2 [3] 4 5 6 7 8 9 ... 20
122
+ when -infinity .. (options[:inner_window] / 2) + 3
123
+ pages[:all][options[:outer_window], options[:inner_window]] +
124
+ [options[:right_cut_label]]
125
+ # allow the inner 'window' to shift left when close to the right edge
126
+ # Ex: 1 2 ... 12 13 14 15 16 [17] 18 19 20
127
+ when (page_count - (options[:inner_window] / 2.0).ceil) - 1 .. infinity
128
+ [options[:left_cut_label]] +
129
+ pages[:all][page_count - options[:inner_window] - options[:outer_window], options[:inner_window]]
130
+ # Display the unshifed window
131
+ # ex: 1 2 ... 5 6 7 [8] 9 10 11 ... 19 20
132
+ else
133
+ [options[:left_cut_label]] +
134
+ pages[:all][current_page - (options[:inner_window] / 2) - 1, options[:inner_window]] +
135
+ [options[:right_cut_label]]
136
+ end
137
+ end
138
+
139
+ b = []
140
+
141
+ [pages[:left], pages[:center], pages[:right]].each do |p|
142
+ p.each do |page_number|
143
+ case page_number
144
+ when String
145
+ b << page_number
146
+ when current_page
147
+ b << Builder::XmlMarkup.new.span(page_number, :class => "this-page")
148
+ when page_count
149
+ b << Builder::XmlMarkup.new.a(page_number, :class => "end", :href => "#{url}=#{page_number}")
150
+ else
151
+ b << Builder::XmlMarkup.new.a(page_number, :href => "#{url}=#{page_number}")
152
+ end
153
+ end
154
+ end
155
+
156
+ b.join(" ")
157
+ end
158
+
159
+ private
160
+
161
+ def infinity
162
+ 1.0 / 0
163
+ end
164
+
165
+ end
166
+ end
167
+ end