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,140 +1,139 @@
1
- require 'dm-core'
2
- require 'dm-validations'
3
- require 'dm-aggregates'
4
-
5
- module MerbAdmin
6
- class AbstractModel
7
- module DatamapperSupport
8
- def get(id)
9
- model.get(id).extend(InstanceMethods)
10
- end
11
-
12
- def count(options = {})
13
- model.count(options.reject{|key, value| [:sort, :sort_reverse].include?(key)})
14
- end
15
-
16
- def first(options = {})
17
- model.first(merge_order(options)).extend(InstanceMethods)
18
- end
19
-
20
- def all(options = {})
21
- model.all(merge_order(options))
22
- end
23
-
24
- def paginated(options = {})
25
- page = options.delete(:page) || 1
26
- per_page = options.delete(:per_page) || MerbAdmin[:per_page]
27
-
28
- page_count = (count(options).to_f / per_page).ceil
29
-
30
- options.merge!({
31
- :limit => per_page,
32
- :offset => (page - 1) * per_page
33
- })
34
-
35
- [page_count, all(options)]
36
- end
37
-
38
- def create(params = {})
39
- model.create(params).extend(InstanceMethods)
40
- end
41
-
42
- def new(params = {})
43
- model.new(params).extend(InstanceMethods)
44
- end
45
-
46
- def destroy_all!
47
- model.all.destroy!
48
- end
49
-
50
- def has_many_associations
51
- associations.select do |association|
52
- association[:type] == :has_many
53
- end
54
- end
55
-
56
- def has_one_associations
57
- associations.select do |association|
58
- association[:type] == :has_one
59
- end
60
- end
61
-
62
- def belongs_to_associations
63
- associations.select do |association|
64
- association[:type] == :belongs_to
65
- end
66
- end
67
-
68
- def associations
69
- model.relationships.to_a.map do |name, association|
70
- {
71
- :name => name,
72
- :pretty_name => name.to_s.gsub("_", " ").capitalize,
73
- :type => association_type_lookup(association),
74
- :parent_model => association.parent_model,
75
- :parent_key => association.parent_key.map{|r| r.name},
76
- :child_model => association.child_model,
77
- :child_key => association.child_key.map{|r| r.name},
78
- }
79
- end
80
- end
81
-
82
- def properties
83
- model.properties.map do |property|
84
- {
85
- :name => property.name,
86
- :pretty_name => property.name.to_s.gsub(/_id$/, "").gsub("_", " ").capitalize,
87
- :type => type_lookup(property),
88
- :length => property.length,
89
- :nullable? => property.allow_nil?,
90
- :serial? => property.serial?,
91
- }
92
- end
93
- end
94
-
95
- private
96
-
97
- def merge_order(options)
98
- @sort ||= options.delete(:sort) || :id
99
- @sort_order ||= options.delete(:sort_reverse) ? :desc : :asc
100
- options.merge(:order => [@sort.to_sym.send(@sort_order)])
101
- end
102
-
103
- def association_type_lookup(association)
104
- if self.model == association.parent_model
105
- association.options[:max] > 1 ? :has_many : :has_one
106
- elsif self.model == association.child_model
107
- :belongs_to
108
- else
109
- raise "Unknown association type"
110
- end
111
- end
112
-
113
- def type_lookup(property)
114
- type = {
115
- BigDecimal => :big_decimal,
116
- DataMapper::Types::Boolean => :boolean,
117
- DataMapper::Types::ParanoidBoolean => :boolean,
118
- DataMapper::Types::ParanoidDateTime => :datetime,
119
- DataMapper::Types::Serial => :integer,
120
- DataMapper::Types::Text => :text,
121
- Date => :date,
122
- DateTime => :datetime,
123
- Fixnum => :integer,
124
- Float => :float,
125
- Integer => :integer,
126
- String => :string,
127
- Time => :time,
128
- }
129
- type[property.type] || type[property.primitive]
130
- end
131
-
132
- module InstanceMethods
133
- def update_attributes(attributes)
134
- update(attributes)
135
- end
136
- end
137
-
138
- end
139
- end
140
- end
1
+ require 'dm-core'
2
+ require 'dm-aggregates'
3
+ require 'dm-types'
4
+ require 'dm-validations'
5
+
6
+ module MerbAdmin
7
+ class AbstractModel
8
+ module DatamapperSupport
9
+ def get(id)
10
+ model.get(id).extend(InstanceMethods)
11
+ end
12
+
13
+ def count(options = {})
14
+ model.count(options.reject{|key, value| [:sort, :sort_reverse].include?(key)})
15
+ end
16
+
17
+ def first(options = {})
18
+ model.first(merge_order(options)).extend(InstanceMethods)
19
+ end
20
+
21
+ def all(options = {})
22
+ model.all(merge_order(options))
23
+ end
24
+
25
+ def paginated(options = {})
26
+ page = options.delete(:page) || 1
27
+ per_page = options.delete(:per_page) || MerbAdmin[:per_page]
28
+
29
+ page_count = (count(options).to_f / per_page).ceil
30
+
31
+ options.merge!({
32
+ :limit => per_page,
33
+ :offset => (page - 1) * per_page
34
+ })
35
+
36
+ [page_count, all(options)]
37
+ end
38
+
39
+ def create(params = {})
40
+ model.create(params).extend(InstanceMethods)
41
+ end
42
+
43
+ def new(params = {})
44
+ model.new(params).extend(InstanceMethods)
45
+ end
46
+
47
+ def destroy_all!
48
+ model.all.destroy!
49
+ end
50
+
51
+ def has_many_associations
52
+ associations.select do |association|
53
+ association[:type] == :has_many
54
+ end
55
+ end
56
+
57
+ def has_one_associations
58
+ associations.select do |association|
59
+ association[:type] == :has_one
60
+ end
61
+ end
62
+
63
+ def belongs_to_associations
64
+ associations.select do |association|
65
+ association[:type] == :belongs_to
66
+ end
67
+ end
68
+
69
+ def associations
70
+ model.relationships.to_a.map do |name, association|
71
+ {
72
+ :name => name,
73
+ :pretty_name => name.to_s.gsub("_", " ").capitalize,
74
+ :type => association_type_lookup(association),
75
+ :parent_model => association.parent_model,
76
+ :parent_key => association.parent_key.map{|r| r.name},
77
+ :child_model => association.child_model,
78
+ :child_key => association.child_key.map{|r| r.name},
79
+ }
80
+ end
81
+ end
82
+
83
+ def properties
84
+ model.properties.map do |property|
85
+ {
86
+ :name => property.name,
87
+ :pretty_name => property.name.to_s.gsub(/_id$/, "").gsub("_", " ").capitalize,
88
+ :type => type_lookup(property),
89
+ :length => property.respond_to?(:length) ? property.length : nil,
90
+ :nullable? => property.allow_nil?,
91
+ :serial? => property.serial?,
92
+ }
93
+ end
94
+ end
95
+
96
+ private
97
+
98
+ def merge_order(options)
99
+ @sort ||= options.delete(:sort) || :id
100
+ @sort_order ||= options.delete(:sort_reverse) ? :desc : :asc
101
+ options.merge(:order => [@sort.to_sym.send(@sort_order)])
102
+ end
103
+
104
+ def association_type_lookup(association)
105
+ if self.model == association.parent_model
106
+ association.options[:max] > 1 ? :has_many : :has_one
107
+ elsif self.model == association.child_model
108
+ :belongs_to
109
+ else
110
+ raise "Unknown association type"
111
+ end
112
+ end
113
+
114
+ def type_lookup(property)
115
+ type = {
116
+ BigDecimal => :big_decimal,
117
+ DataMapper::Types::Boolean => :boolean,
118
+ DataMapper::Types::Serial => :integer,
119
+ DataMapper::Types::Text => :text,
120
+ Date => :date,
121
+ DateTime => :datetime,
122
+ Fixnum => :integer,
123
+ Float => :float,
124
+ Integer => :integer,
125
+ String => :string,
126
+ Time => :time,
127
+ }
128
+ type[property.type] || type[property.primitive]
129
+ end
130
+
131
+ module InstanceMethods
132
+ def update_attributes(attributes)
133
+ update(attributes)
134
+ end
135
+ end
136
+
137
+ end
138
+ end
139
+ end
@@ -1,13 +1,13 @@
1
- module MerbAdmin
2
- class AbstractModel
3
- module GenericSupport
4
- def to_param
5
- model.to_s.snake_case
6
- end
7
-
8
- def pretty_name
9
- model.to_s.snake_case.gsub('_', ' ').capitalize
10
- end
11
- end
12
- end
13
- end
1
+ module MerbAdmin
2
+ class AbstractModel
3
+ module GenericSupport
4
+ def to_param
5
+ model.to_s.snake_case
6
+ end
7
+
8
+ def pretty_name
9
+ model.to_s.snake_case.gsub('_', ' ').capitalize
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/merb-admin.rb CHANGED
@@ -1,99 +1,99 @@
1
- if defined?(Merb::Plugins)
2
-
3
- $:.unshift File.dirname(__FILE__)
4
-
5
- Merb::Plugins.add_rakefiles "merb-admin/merbtasks", "merb-admin/slicetasks", "merb-admin/spectasks"
6
-
7
- # Register the Slice for the current host application
8
- Merb::Slices::register(__FILE__)
9
-
10
- # Slice configuration - set this in a before_app_loads callback.
11
- # By default a Slice uses its own layout, so you can swicht to
12
- # the main application layout or no layout at all if needed.
13
- #
14
- # Configuration options:
15
- # :layout - the layout to use; defaults to :merb-admin
16
- # :mirror - which path component types to use on copy operations; defaults to all
17
- Merb::Slices::config[:merb_admin][:layout] ||= :merb_admin
18
- Merb::Slices::config[:merb_admin][:per_page] ||= 100
19
- Merb::Slices::config[:merb_admin][:excluded_models] ||= []
20
-
21
- # All Slice code is expected to be namespaced inside a module
22
- module MerbAdmin
23
-
24
- # Slice metadata
25
- self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
26
- self.version = "0.8.1"
27
- self.author = "Erik Michaels-Ober"
28
-
29
- # Stub classes loaded hook - runs before LoadClasses BootLoader
30
- # right after a slice's classes have been loaded internally.
31
- def self.loaded
32
- end
33
-
34
- # Initialization hook - runs before AfterAppLoads BootLoader
35
- def self.init
36
- end
37
-
38
- # Activation hook - runs after AfterAppLoads BootLoader
39
- def self.activate
40
- end
41
-
42
- # Deactivation hook - triggered by Merb::Slices.deactivate(MerbAdmin)
43
- def self.deactivate
44
- end
45
-
46
- def self.setup_router(scope)
47
- scope.match("/", :method => :get).
48
- to(:controller => "main", :action => "index").
49
- name(:dashboard)
50
-
51
- scope.match("/:model_name", :method => :get).
52
- to(:controller => "main", :action => "list").
53
- name(:list)
54
-
55
- scope.match("/:model_name/new", :method => :get).
56
- to(:controller => "main", :action => "new").
57
- name(:new)
58
-
59
- scope.match("/:model_name/:id/edit", :method => :get).
60
- to(:controller => "main", :action => "edit").
61
- name(:edit)
62
-
63
- scope.match("/:model_name", :method => :post).
64
- to(:controller => "main", :action => "create").
65
- name(:create)
66
-
67
- scope.match("/:model_name/:id", :method => :put).
68
- to(:controller => "main", :action => "update").
69
- name(:update)
70
-
71
- scope.match("/:model_name/:id/delete", :method => :get).
72
- to(:controller => "main", :action => "delete").
73
- name(:delete)
74
-
75
- scope.match("/:model_name/:id(.:format)", :method => :delete).
76
- to(:controller => "main", :action => "destroy").
77
- name(:destroy)
78
- end
79
-
80
- end
81
-
82
- # Setup the slice layout for MerbAdmin
83
- #
84
- # Use MerbAdmin.push_path and MerbAdmin.push_app_path
85
- # to set paths to merb-admin-level and app-level paths. Example:
86
- #
87
- # MerbAdmin.push_path(:application, MerbAdmin.root)
88
- # MerbAdmin.push_app_path(:application, Merb.root / 'slices' / 'merb-admin')
89
- # ...
90
- #
91
- # Any component path that hasn't been set will default to MerbAdmin.root
92
- #
93
- # Or just call setup_default_structure! to setup a basic Merb MVC structure.
94
- MerbAdmin.setup_default_structure!
95
-
96
- # Add dependencies for other MerbAdmin classes below. Example:
97
- # dependency "merb-admin/other"
98
-
99
- end
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ Merb::Plugins.add_rakefiles "merb-admin/merbtasks", "merb-admin/slicetasks", "merb-admin/spectasks"
6
+
7
+ # Register the Slice for the current host application
8
+ Merb::Slices::register(__FILE__)
9
+
10
+ # Slice configuration - set this in a before_app_loads callback.
11
+ # By default a Slice uses its own layout, so you can swicht to
12
+ # the main application layout or no layout at all if needed.
13
+ #
14
+ # Configuration options:
15
+ # :layout - the layout to use; defaults to :merb-admin
16
+ # :mirror - which path component types to use on copy operations; defaults to all
17
+ Merb::Slices::config[:merb_admin][:layout] ||= :merb_admin
18
+ Merb::Slices::config[:merb_admin][:per_page] ||= 100
19
+ Merb::Slices::config[:merb_admin][:excluded_models] ||= []
20
+
21
+ # All Slice code is expected to be namespaced inside a module
22
+ module MerbAdmin
23
+
24
+ # Slice metadata
25
+ self.description = "MerbAdmin is a Merb plugin that provides an easy-to-use interface for managing your data."
26
+ self.version = "0.8.3"
27
+ self.author = "Erik Michaels-Ober"
28
+
29
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
30
+ # right after a slice's classes have been loaded internally.
31
+ def self.loaded
32
+ end
33
+
34
+ # Initialization hook - runs before AfterAppLoads BootLoader
35
+ def self.init
36
+ end
37
+
38
+ # Activation hook - runs after AfterAppLoads BootLoader
39
+ def self.activate
40
+ end
41
+
42
+ # Deactivation hook - triggered by Merb::Slices.deactivate(MerbAdmin)
43
+ def self.deactivate
44
+ end
45
+
46
+ def self.setup_router(scope)
47
+ scope.match("/", :method => :get).
48
+ to(:controller => "main", :action => "index").
49
+ name(:dashboard)
50
+
51
+ scope.match("/:model_name", :method => :get).
52
+ to(:controller => "main", :action => "list").
53
+ name(:list)
54
+
55
+ scope.match("/:model_name/new", :method => :get).
56
+ to(:controller => "main", :action => "new").
57
+ name(:new)
58
+
59
+ scope.match("/:model_name/:id/edit", :method => :get).
60
+ to(:controller => "main", :action => "edit").
61
+ name(:edit)
62
+
63
+ scope.match("/:model_name", :method => :post).
64
+ to(:controller => "main", :action => "create").
65
+ name(:create)
66
+
67
+ scope.match("/:model_name/:id", :method => :put).
68
+ to(:controller => "main", :action => "update").
69
+ name(:update)
70
+
71
+ scope.match("/:model_name/:id/delete", :method => :get).
72
+ to(:controller => "main", :action => "delete").
73
+ name(:delete)
74
+
75
+ scope.match("/:model_name/:id(.:format)", :method => :delete).
76
+ to(:controller => "main", :action => "destroy").
77
+ name(:destroy)
78
+ end
79
+
80
+ end
81
+
82
+ # Setup the slice layout for MerbAdmin
83
+ #
84
+ # Use MerbAdmin.push_path and MerbAdmin.push_app_path
85
+ # to set paths to merb-admin-level and app-level paths. Example:
86
+ #
87
+ # MerbAdmin.push_path(:application, MerbAdmin.root)
88
+ # MerbAdmin.push_app_path(:application, Merb.root / 'slices' / 'merb-admin')
89
+ # ...
90
+ #
91
+ # Any component path that hasn't been set will default to MerbAdmin.root
92
+ #
93
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
94
+ MerbAdmin.setup_default_structure!
95
+
96
+ # Add dependencies for other MerbAdmin classes below. Example:
97
+ # dependency "merb-admin/other"
98
+
99
+ end