core-generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/README.textile +51 -0
  4. data/Rakefile +2 -0
  5. data/core-generators.gemspec +21 -0
  6. data/lib/core-generators.rb +6 -0
  7. data/lib/core/inherited_resource_controller.rb +10 -0
  8. data/lib/core/paginated_controller.rb +12 -0
  9. data/lib/core/version.rb +3 -0
  10. data/lib/generators/core/install/install_generator.rb +132 -0
  11. data/lib/generators/core/install/templates/bootstrap.rake +43 -0
  12. data/lib/generators/core/install/templates/locales/core.en.yml +20 -0
  13. data/lib/generators/core/install/templates/locales/core.es.yml +17 -0
  14. data/lib/generators/core/install/templates/settings.yml +17 -0
  15. data/lib/generators/core/install/templates/simple_form_custom.rb +58 -0
  16. data/lib/generators/core/layout/layout_generator.rb +42 -0
  17. data/lib/generators/core/layout/templates/core.js +113 -0
  18. data/lib/generators/core/layout/templates/core_helper.rb +114 -0
  19. data/lib/generators/core/layout/templates/images/arrow.png +0 -0
  20. data/lib/generators/core/layout/templates/images/boxbar-background.png +0 -0
  21. data/lib/generators/core/layout/templates/images/button-background-active.png +0 -0
  22. data/lib/generators/core/layout/templates/images/button-background.png +0 -0
  23. data/lib/generators/core/layout/templates/images/buttons/cross.png +0 -0
  24. data/lib/generators/core/layout/templates/images/buttons/edit.png +0 -0
  25. data/lib/generators/core/layout/templates/images/buttons/key.png +0 -0
  26. data/lib/generators/core/layout/templates/images/buttons/tick.png +0 -0
  27. data/lib/generators/core/layout/templates/images/menubar-background.png +0 -0
  28. data/lib/generators/core/layout/templates/stylesheets/base.sass +366 -0
  29. data/lib/generators/core/layout/templates/stylesheets/override.sass +1 -0
  30. data/lib/generators/core/layout/templates/stylesheets/style.sass +434 -0
  31. data/lib/generators/core/layout/templates/views/haml/_sidebar.html.haml +14 -0
  32. data/lib/generators/core/layout/templates/views/haml/layout.html.haml +38 -0
  33. data/lib/generators/core/scaffold/scaffold_generator.rb +125 -0
  34. data/lib/generators/core/scaffold/templates/controller.rb +10 -0
  35. data/lib/generators/core/scaffold/templates/helper.rb +3 -0
  36. data/lib/generators/core/scaffold/templates/migration.rb +16 -0
  37. data/lib/generators/core/scaffold/templates/model.rb +5 -0
  38. data/lib/generators/core/scaffold/templates/views/haml/_collection.html.haml +25 -0
  39. data/lib/generators/core/scaffold/templates/views/haml/_form.html.haml +13 -0
  40. data/lib/generators/core/scaffold/templates/views/haml/_search.html.haml +7 -0
  41. data/lib/generators/core/scaffold/templates/views/haml/edit.html.haml +11 -0
  42. data/lib/generators/core/scaffold/templates/views/haml/index.html.haml +8 -0
  43. data/lib/generators/core/scaffold/templates/views/haml/index.js.haml +1 -0
  44. data/lib/generators/core/scaffold/templates/views/haml/new.html.haml +12 -0
  45. data/lib/generators/core/scaffold/templates/views/haml/show.html.haml +19 -0
  46. metadata +112 -0
@@ -0,0 +1,113 @@
1
+ function remove_fields(link) {
2
+ $(link).prev("input[type=hidden]").val("1");
3
+ $(link).closest(".fields").hide();
4
+ }
5
+
6
+ function add_fields(link, association, content) {
7
+ var new_id = new Date().getTime();
8
+ var regexp = new RegExp("new_" + association, "g")
9
+ $(link).parent().before(content.replace(regexp, new_id));
10
+ }
11
+
12
+
13
+ function number_to_currency(number, options) {
14
+ try {
15
+ var options = options || {};
16
+ var precision = options["precision"] || 2;
17
+ var unit = options["unit"] || "$";
18
+ var separator = precision > 0 ? options["separator"] || "." : "";
19
+ var delimiter = options["delimiter"] || ",";
20
+
21
+ var parts = parseFloat(number).toFixed(precision).split('.');
22
+ return number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
23
+ } catch(e) {
24
+ return number
25
+ }
26
+ }
27
+
28
+ function number_with_delimiter(number, delimiter, separator) {
29
+ try {
30
+ var delimiter = delimiter || ",";
31
+ var separator = separator || ".";
32
+
33
+ var parts = number.toString().split('.');
34
+ parts[0] = parts[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1" + delimiter);
35
+ return parts.join(separator);
36
+ } catch(e) {
37
+ return number
38
+ }
39
+ }
40
+
41
+ jQuery.ajaxSetup({
42
+ beforeSend: function(xhr) {
43
+ xhr.setRequestHeader("Accept", "text/javascript");
44
+ }
45
+ });
46
+
47
+ var common = {
48
+ setupAjaxCallbacks: function() {
49
+ $('body').ajaxStart(function () {
50
+ $('#global-spinner').animate({ marginTop: "0px"});
51
+ });
52
+ $('body').ajaxStop(function () {
53
+ $('#global-spinner').animate({ marginTop: "-30px"});
54
+ });
55
+ $('body').ajaxError(function (event, xhr, ajaxOptions, thrownError) {
56
+ if (xhr.status === 401) {
57
+ if ($("#login").is(":hidden")) {
58
+ app.showLoginForm();
59
+ }
60
+ alert("Sorry, " + xhr.responseText.toLowerCase());
61
+ }
62
+ });
63
+ },
64
+ setupAjaxCallbacksForScaffoldResources: function() {
65
+ $('a.sort_link, .pagination a').live('click', function() {
66
+ $('#results').load(this.href + '');
67
+ return false;
68
+ });
69
+ $('form.search').ajaxForm({target: '#results'});
70
+ },
71
+ setupCommonEventHandlers: function() {
72
+ $("form input[type='text']:first").focus();
73
+
74
+ setTimeout(common.hideFlashes, 5000);
75
+ },
76
+
77
+ hideFlashes : function() {
78
+ var self = this;
79
+ var flash_messages = $(".flash .message").not(".sticky");
80
+ flash_messages.each(function(index) {
81
+ $(flash_messages[index]).delay(5000).fadeOut(3000);
82
+ });
83
+ },
84
+
85
+ // Collapsable Boxes
86
+ setupToggledBoxes: function() {
87
+
88
+ // Expanded Link
89
+ $(".toggle h2 .collapsed-link").click(function() {
90
+ $(this).siblings('.expanded-link').show();
91
+ $(this).hide();
92
+ common.contentFor($(this)).hide();
93
+ });
94
+
95
+ // Collapsed Link
96
+ $(".toggle h2 .expanded-link").click(function() {
97
+ $(this).siblings('.collapsed-link').show();
98
+ $(this).hide();
99
+ common.contentFor($(this)).show();
100
+ });
101
+
102
+ },
103
+ contentFor: function(element){
104
+ return element.parents("h2").siblings('.content');
105
+ }
106
+ }
107
+ $(function(){
108
+ common.setupAjaxCallbacks();
109
+ common.setupAjaxCallbacksForScaffoldResources();
110
+ common.setupCommonEventHandlers();
111
+ common.setupToggledBoxes();
112
+ });
113
+
@@ -0,0 +1,114 @@
1
+ module CoreHelper
2
+ def flashes
3
+ haml_tag '.flash' do
4
+ flash.each do |type, message|
5
+ haml_tag :div, {:class => "message #{type}"} do
6
+ haml_tag :p, message
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ def sidebar
13
+ yield
14
+ content_for :sidebar, render('shared/sidebar')
15
+ end
16
+
17
+ def yes_no(value)
18
+ value ? I18n.t('show_for.yes') : I18n.t('show_for.no')
19
+ end
20
+
21
+ def navigation_list
22
+ content_for(:actions) do
23
+ haml_tag 'ul.navigation' do
24
+ yield
25
+ end
26
+ end
27
+ end
28
+
29
+ def extra_content(title = nil, &block)
30
+ content_for(:extra) do
31
+ haml_tag 'div.block.notice' do
32
+ haml_tag("h3", title) if title
33
+ haml_tag "div.content" do
34
+ yield
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def action_links_for_current_action
41
+ case params[:action]
42
+ when 'index' then
43
+ action_link_to('new')
44
+ when 'edit' then
45
+ action_link_to('show')
46
+ action_link_to('new')
47
+ action_link_to('list')
48
+ when 'new' then
49
+ action_link_to('list')
50
+ when 'show' then
51
+ action_link_to('edit')
52
+ action_link_to('new')
53
+ action_link_to('list')
54
+ end
55
+ end
56
+
57
+ def action_link_to(name, url = nil)
58
+ if crud_actions.include?(name)
59
+ resource_name = resource_class.human_name
60
+ resource_name = resource_name.pluralize if name == "list"
61
+ end
62
+
63
+ url ||= url_for_name(name)
64
+ link = link_to(t("core.#{name}" , :default => "#{name.humanize} #{resource_name}"), url)
65
+ haml_tag :li, link
66
+ end
67
+
68
+ def toggle_box(title, collapsed = true)
69
+ haml_tag :div, :class => 'toggle' do
70
+ haml_tag :h2 do
71
+ haml_concat title
72
+ haml_tag "span.small.expanded-link", "[view]", (collapsed ? {} : { :class => 'hide' } )
73
+ haml_tag "span.small.collapsed-link", "[hide]", (collapsed ? { :class => 'hide' } : {} )
74
+ end
75
+ haml_tag ".content", (collapsed ? { :class => 'hide' } : {} ) do
76
+ yield
77
+ end
78
+ end
79
+ end
80
+
81
+ def url_for_name(name)
82
+ case name
83
+ when 'new' then new_resource_path
84
+ when 'edit' then edit_resource_path
85
+ when 'show' then resource_path
86
+ when 'destroy' then resource_path
87
+ when 'list' then collection_path
88
+ end
89
+ end
90
+
91
+ def show_content_if(content, &block)
92
+ if content.present?
93
+ content + with_output_buffer(&block)
94
+ end
95
+ end
96
+
97
+ def content_block(title = "")
98
+ haml_tag '.content' do
99
+ haml_tag :h2, :class => "title" do
100
+ haml_concat title
101
+ end
102
+ haml_tag ".inner" do
103
+ yield
104
+ end
105
+ end
106
+ end
107
+
108
+ private
109
+
110
+ def crud_actions
111
+ %w(list edit new show destroy)
112
+ end
113
+
114
+ end
@@ -0,0 +1,366 @@
1
+ *
2
+ margin: 0
3
+ padding: 0
4
+
5
+ .clear
6
+ clear: both
7
+ height: 0
8
+
9
+ .wat-cf
10
+ &:after
11
+ content: "."
12
+ display: block
13
+ height: 0
14
+ clear: both
15
+ visibility: hidden
16
+ display: inline-block
17
+
18
+ /* Hides from IE-mac */
19
+
20
+ * html .wat-cf
21
+ height: 1%
22
+
23
+ .wat-cf
24
+ display: block
25
+
26
+ /* End hide from IE-mac */
27
+
28
+ h1
29
+ margin: 15px 0
30
+ font-size: 22px
31
+ font-weight: normal
32
+
33
+ h2
34
+ font-size: 22px
35
+ margin: 15px 0
36
+ font-weight: normal
37
+
38
+ h3
39
+ font-size: 18px
40
+ margin: 10px 0
41
+ font-weight: normal
42
+
43
+ h4
44
+ font-size: 16px
45
+ margin: 10px 0
46
+ font-weight: normal
47
+
48
+ hr
49
+ height: 1px
50
+ border: 0
51
+
52
+ p
53
+ margin: 15px 0
54
+
55
+ a img
56
+ border: none
57
+
58
+ body
59
+ font-size: 12px
60
+ font-family: sans-serif
61
+
62
+ #container
63
+ min-width: 960px
64
+
65
+ #header, #wrapper
66
+ padding: 0 20px
67
+
68
+ #header
69
+ position: relative
70
+ padding-top: 1px
71
+ h1
72
+ margin: 0
73
+ padding: 10px 0
74
+ font-size: 26px
75
+ a
76
+ &:link, &:active, &:hover, &:visited
77
+ text-decoration: none
78
+
79
+ #main
80
+ width: 70%
81
+ float: left
82
+
83
+ .actions-bar
84
+ padding: 10px 1px
85
+ .actions
86
+ float: left
87
+ .pagination
88
+ float: right
89
+ padding: 1px 0
90
+
91
+ #sidebar
92
+ width: 25%
93
+ float: right
94
+ h3
95
+ padding: 10px 15px
96
+ margin: 0
97
+ font-size: 13px
98
+ .block
99
+ margin-bottom: 20px
100
+ padding-bottom: 10px
101
+ .content
102
+ padding: 0 15px
103
+ ul.navigation li a
104
+ &:link, &:visited
105
+ display: block
106
+ padding: 10px 15px
107
+ .block .sidebar-block, .notice
108
+ padding: 10px
109
+
110
+ #wrapper
111
+ padding-top: 20px
112
+
113
+ #main
114
+ .block
115
+ margin-bottom: 20px
116
+ padding-top: 1px
117
+ .content .inner
118
+ padding: 0 15px 15px
119
+ .main p.first
120
+ margin-top: 0
121
+
122
+ #user-navigation
123
+ position: absolute
124
+ top: 0px
125
+ right: 20px
126
+
127
+ #main-navigation
128
+ width: 100%
129
+
130
+ #user-navigation ul, #main-navigation ul, .secondary-navigation ul, #sidebar ul.navigation
131
+ margin: 0
132
+ padding: 0
133
+ list-style-type: none
134
+
135
+ #user-navigation ul li, #main-navigation ul li, .secondary-navigation ul li
136
+ float: left
137
+
138
+ #main-navigation ul li
139
+ margin-right: 5px
140
+
141
+ #user-navigation ul li
142
+ padding: 5px 10px
143
+
144
+ #main-navigation ul li a
145
+ &:link, &:visited, &:hover, &:active
146
+ text-decoration: none
147
+
148
+ .secondary-navigation ul li a
149
+ &:link, &:visited, &:hover, &:active
150
+ text-decoration: none
151
+
152
+ #user-navigation ul li a
153
+ &:link, &:visited, &:hover, &:active
154
+ text-decoration: none
155
+
156
+ #main-navigation ul li a
157
+ font-size: 14px
158
+ line-height: 14px
159
+ display: block
160
+ padding: 8px 15px
161
+
162
+ .secondary-navigation
163
+ font-size: 13px
164
+ border-bottom-width: 10px
165
+ border-bottom-style: solid
166
+ ul li a
167
+ display: block
168
+ padding: 10px 15px
169
+
170
+ #footer
171
+ padding-bottom: 20px
172
+
173
+ /* pagination */
174
+
175
+ .pagination
176
+ a, span
177
+ padding: 2px 5px
178
+ margin-right: 5px
179
+ display: block
180
+ float: left
181
+ border-style: solid
182
+ border-width: 1px
183
+ em
184
+ padding: 2px 5px
185
+ margin-right: 5px
186
+ display: block
187
+ float: left
188
+ border-style: solid
189
+ border-width: 1px
190
+ font-weight: bold
191
+ a
192
+ text-decoration: none
193
+
194
+ /* tables */
195
+
196
+ .table
197
+ width: 100%
198
+ border-collapse: collapse
199
+ margin-bottom: 15px
200
+ th
201
+ padding: 10px
202
+ font-weight: bold
203
+ text-align: left
204
+ &.first
205
+ width: 30px
206
+ &.last
207
+ width: 200px
208
+ .checkbox
209
+ margin-left: 10px
210
+ td
211
+ padding: 10px
212
+ &.last
213
+ text-align: right
214
+
215
+ /* forms */
216
+
217
+ input.checkbox
218
+ margin: 0
219
+ padding: 0
220
+
221
+ .form
222
+ .group
223
+ margin-bottom: 15px
224
+ div
225
+ &.left
226
+ width: 20%
227
+ float: left
228
+ &.right
229
+ width: 75%
230
+ float: right
231
+ .columns
232
+ .column
233
+ width: 48%
234
+ .left
235
+ float: left
236
+ .right
237
+ float: right
238
+ label.label, input.text_field, textarea.text_area
239
+ font-size: 1.2em
240
+ padding: 1px 0
241
+ margin: 0
242
+ label.right
243
+ text-align: right
244
+ input
245
+ &.checkbox, &.radio
246
+ margin-right: 5px
247
+ label
248
+ &.checkbox, &.radio
249
+ line-height: 1.5em
250
+ &.label
251
+ display: block
252
+ padding-bottom: 2px
253
+ font-weight: bold
254
+ div.fieldWithErrors label.label
255
+ display: inline
256
+ .fieldWithErrors .error
257
+ color: red
258
+ input.text_field, textarea.text_area
259
+ width: 100%
260
+ border-width: 1px
261
+ border-style: solid
262
+
263
+ /* lists */
264
+
265
+ ul.list
266
+ margin: 0
267
+ padding: 0
268
+ list-style-type: none
269
+ li
270
+ clear: left
271
+ padding-bottom: 5px
272
+ .left
273
+ float: left
274
+ .avatar
275
+ width: 50px
276
+ height: 50px
277
+ .item
278
+ margin-left: 80px
279
+ .avatar
280
+ float: left
281
+ margin: 0 5px 5px 0
282
+ width: 30px
283
+ height: 30px
284
+
285
+ /* box */
286
+
287
+ #box
288
+ width: 500px
289
+ margin: 50px auto
290
+ .block
291
+ margin-bottom: 20px
292
+ h2
293
+ padding: 10px 15px
294
+ margin: 0
295
+ .content
296
+ padding: 10px 20px
297
+
298
+ /* Inspired by http://particletree.com/features/rediscovering-the-button-element */
299
+
300
+ a.button
301
+ &:link, &:visited, &:hover, &:active
302
+ color: #222
303
+ display: block
304
+ float: left
305
+ margin: 0 7px 0 0
306
+ background-color: #eee
307
+ border: 1px solid #bfbfbf
308
+ font-size: 1em
309
+ line-height: 1.3em
310
+ font-weight: bold
311
+ cursor: pointer
312
+ padding: 5px 10px 6px 7px
313
+ text-decoration: none
314
+
315
+ button.button
316
+ color: #222
317
+ display: block
318
+ float: left
319
+ margin: 0 7px 0 0
320
+ background-color: #eee
321
+ border: 1px solid #bfbfbf
322
+ font-size: 1em
323
+ line-height: 1.3em
324
+ font-weight: bold
325
+ cursor: pointer
326
+ padding: 5px 10px 6px 7px
327
+ text-decoration: none
328
+ width: auto
329
+ overflow: visible
330
+ padding: 4px 10px 3px 7px
331
+ /* IE6 */
332
+ &[type]
333
+ padding: 5px 10px 5px 7px
334
+ /* Firefox */
335
+ line-height: 17px
336
+ /* Safari */
337
+
338
+ *:first-child + html button.button[type]
339
+ padding: 4px 10px 3px 7px
340
+ /* IE7 */
341
+
342
+ button.button img, a.button img
343
+ margin: 0 3px -3px 0 !important
344
+ padding: 0
345
+ border: none
346
+ width: 16px
347
+ height: 16px
348
+
349
+ button.button:hover, a.button:hover
350
+ background-color: #dedede
351
+
352
+ button.button:active, a.button:active
353
+ background-color: #e5e5e5
354
+
355
+ .text_button_padding
356
+ color: #222222
357
+ display: block
358
+ float: left
359
+ font-size: 1em
360
+ line-height: 2em
361
+ margin: 0 7px 0 0
362
+ padding: 5px 0 6px 7px
363
+ text-decoration: none
364
+
365
+ .link_button
366
+ cursor: pointer