beautiful_scaffold 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/beautiful_scaffold.gemspec +1 -1
  2. data/lib/generators/USAGE +0 -3
  3. data/lib/generators/beautiful_migration_generator.rb +13 -2
  4. data/lib/generators/beautiful_scaffold_common_methods.rb +4 -1
  5. data/lib/generators/beautiful_scaffold_generator.rb +35 -8
  6. data/lib/generators/templates/app/assets/images/glyphicons-halflings-white.png +0 -0
  7. data/lib/generators/templates/app/assets/images/glyphicons-halflings.png +0 -0
  8. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +49 -73
  9. data/lib/generators/templates/app/assets/javascripts/bootstrap-alert.js +90 -0
  10. data/lib/generators/templates/app/assets/javascripts/bootstrap-dropdown.js +100 -0
  11. data/lib/generators/templates/app/assets/javascripts/bootstrap-modal.js +218 -0
  12. data/lib/generators/templates/app/assets/javascripts/bootstrap-tooltip.js +275 -0
  13. data/lib/generators/templates/app/assets/javascripts/bootstrap.js +1825 -0
  14. data/lib/generators/templates/app/assets/javascripts/bootstrap.min.js +6 -0
  15. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +88 -0
  16. data/lib/generators/templates/app/assets/stylesheets/bootstrap-responsive.css +815 -0
  17. data/lib/generators/templates/app/assets/stylesheets/bootstrap-responsive.min.css +9 -0
  18. data/lib/generators/templates/app/assets/stylesheets/bootstrap.css +4983 -0
  19. data/lib/generators/templates/app/assets/stylesheets/bootstrap.min.css +9 -0
  20. data/lib/generators/templates/app/controllers/base.rb +3 -2
  21. data/lib/generators/templates/app/controllers/master_base.rb +22 -1
  22. data/lib/generators/templates/app/helpers/beautiful_helper.rb +75 -56
  23. data/lib/generators/templates/app/initializers/link_renderer.rb +51 -0
  24. data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +6 -2
  25. data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +7 -3
  26. data/lib/generators/templates/app/views/_beautiful_menu.html.erb +1 -9
  27. data/lib/generators/templates/app/views/_form.html.erb +3 -3
  28. data/lib/generators/templates/app/views/_modal_columns.html.erb +41 -0
  29. data/lib/generators/templates/app/views/dashboard.html.erb +0 -0
  30. data/lib/generators/templates/app/views/edit.html.erb +5 -6
  31. data/lib/generators/templates/app/views/index.html.erb +87 -74
  32. data/lib/generators/templates/app/views/layout.html.erb +77 -41
  33. data/lib/generators/templates/app/views/new.html.erb +5 -5
  34. data/lib/generators/templates/app/views/partials/_form_field.html.erb +45 -25
  35. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +2 -2
  36. data/lib/generators/templates/app/views/partials/_index_column.html.erb +1 -1
  37. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  38. data/lib/generators/templates/app/views/show.html.erb +8 -7
  39. metadata +18 -11
  40. data/lib/generators/templates/app/assets/images/bg-bottom-login.jpg +0 -0
  41. data/lib/generators/templates/app/assets/images/bg-error.png +0 -0
  42. data/lib/generators/templates/app/assets/images/bg-left.jpg +0 -0
  43. data/lib/generators/templates/app/assets/images/bg-notice.jpg +0 -0
  44. data/lib/generators/templates/app/assets/images/bg-notice.png +0 -0
  45. data/lib/generators/templates/app/assets/images/bg-success.png +0 -0
  46. data/lib/generators/templates/app/assets/images/bg-top-login.jpg +0 -0
  47. data/lib/generators/templates/app/assets/images/bg-warning.png +0 -0
  48. data/lib/generators/templates/app/assets/stylesheets/beautiful_scaffold.css.scss +0 -719
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "beautiful_scaffold"
6
- s.version = "0.0.8"
6
+ s.version = "0.1.0"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.summary = "Beautiful Scaffold generate fully customizable scaffold"
9
9
  s.email = "claudel.sylvain@gmail.com"
@@ -9,7 +9,4 @@ Example:
9
9
  rails generate beautiful_migration AddColorToProducts color:string
10
10
 
11
11
  rails generate beautiful_locale {fr|en|all}
12
-
13
- This will create:
14
- what/will/it/create
15
12
 
@@ -30,8 +30,19 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
30
30
  end
31
31
 
32
32
  def generate_model
33
- generate("migration", "#{name} #{beautiful_attr_to_rails_attr.join(' ')} #{@fulltext_field.join(' ')}")
34
- # TODO pour les references mettre _id et integer
33
+ generate("migration", "#{name} #{beautiful_attr_to_rails_attr(true).join(' ')} #{@fulltext_field.join(' ')}")
34
+ end
35
+
36
+ def add_to_model
37
+ myattributes.each{ |attr|
38
+ a,t = attr.split(':')
39
+ if ['references', 'reference'].include?(t) then
40
+ inject_into_file("app/models/#{model}.rb", "\n belongs_to :#{a}", :after => "ActiveRecord::Base")
41
+ inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
42
+ a += "_id"
43
+ end
44
+ inject_into_file("app/models/#{model}.rb", ":#{a}, ", :after => "attr_accessible ")
45
+ }
35
46
  end
36
47
 
37
48
  def generate_views
@@ -69,7 +69,7 @@ module BeautifulScaffoldCommonMethods
69
69
  }
70
70
  end
71
71
 
72
- def beautiful_attr_to_rails_attr
72
+ def beautiful_attr_to_rails_attr(for_migration = false)
73
73
  newmyattributes = []
74
74
  myattributes.each{ |attr|
75
75
  a,t = attr.split(':')
@@ -78,6 +78,9 @@ module BeautifulScaffoldCommonMethods
78
78
  newt = 'text'
79
79
  elsif t == 'price' then
80
80
  newt = 'float'
81
+ elsif ['references', 'reference'].include?(t) and for_migration then
82
+ a = a + '_id'
83
+ newt = 'integer:index'
81
84
  end
82
85
 
83
86
  newmyattributes << [a, newt].join(':')
@@ -47,15 +47,28 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
47
47
 
48
48
  # Css
49
49
  reset = "#{stylesheetspath}reset.css"
50
- bc_css = "#{stylesheetspath}beautiful_scaffold.css.scss"
50
+ bc_css = [
51
+ "#{stylesheetspath}bootstrap.css",
52
+ "#{stylesheetspath}bootstrap.min.css",
53
+ "#{stylesheetspath}bootstrap-responsive.css",
54
+ "#{stylesheetspath}bootstrap-responsive.min.css",
55
+ "#{stylesheetspath}beautiful-scaffold.css.scss"
56
+ ]
51
57
 
52
58
  javascriptspath = "app/assets/javascripts/"
53
59
 
54
60
  # Js
55
- bc_js = "#{javascriptspath}beautiful_scaffold.js"
61
+ bc_js = [
62
+ "#{javascriptspath}bootstrap.js",
63
+ "#{javascriptspath}bootstrap.min.js",
64
+ "#{javascriptspath}bootstrap-alert.js",
65
+ "#{javascriptspath}bootstrap-dropdown.js",
66
+ "#{javascriptspath}bootstrap-modal.js",
67
+ "#{javascriptspath}bootstrap-tooltip.js"
68
+ ]
56
69
  pjax_js = "#{javascriptspath}jquery.pjax.js"
57
70
 
58
- [reset, bc_css, bc_js, pjax_js].each{ |path|
71
+ [reset, bc_css, bc_js, pjax_js].flatten.each{ |path|
59
72
  copy_file path, path
60
73
  }
61
74
 
@@ -69,13 +82,15 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
69
82
  if not File.exist?("app/views/layouts/_beautiful_menu.html.erb") then
70
83
  template "app/views/_beautiful_menu.html.erb", "app/views/layouts/_beautiful_menu.html.erb"
71
84
  end
85
+
86
+ empty_directory "app/views/beautiful"
87
+ template "app/views/dashboard.html.erb", "app/views/beautiful/dashboard.html.erb"
88
+ copy_file "app/views/_modal_columns.html.erb", "app/views/layouts/_modal_columns.html.erb"
72
89
 
73
90
  inject_into_file("app/views/layouts/_beautiful_menu.html.erb",'
74
- <p class="menuelt <%= "active" if params[:controller] == "' + namespace_for_url + model.pluralize + '" %>" data-id="sub-' + model + '">' + model.capitalize + '</p>
75
- <ul class="submenu <%= "hidden" if params[:controller] != "' + namespace_for_url + model.pluralize + '" %>" id="sub-' + model + '">
76
- <li><%= link_to "New ' + model.capitalize + '", new_' + namespace_for_route + model + '_path %></li>
77
- <li><%= link_to "Manage ' + model.capitalize.pluralize + '", ' + namespace_for_route + model.pluralize + '_path %></li>
78
- </ul>', :after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
91
+ <li class="<%= "active" if params[:controller] == "' + namespace_for_url + model.pluralize + '" %>">
92
+ <%= link_to "' + model.capitalize.pluralize + '", ' + namespace_for_route + model.pluralize + '_path %>
93
+ </li>', :after => "<!-- Beautiful Scaffold Menu Do Not Touch This -->")
79
94
  end
80
95
 
81
96
  def install_markitup
@@ -152,7 +167,19 @@ class BeautifulScaffoldGenerator < Rails::Generators::Base
152
167
  end
153
168
  end
154
169
 
170
+ def install_willpaginate_renderer_for_bootstrap
171
+ copy_file "app/initializers/link_renderer.rb", "config/initializers/beautiful_helper.rb"
172
+ end
173
+
155
174
  def routes
175
+ routes_in_text = File.read("config/routes.rb")
176
+
177
+ if not routes_in_text[/beautiful#dashboard/] and not routes_in_text[/beautiful#select_fields/] then
178
+ myroute = "root :to => 'beautiful#dashboard'\n"
179
+ myroute += " match ':model_sym/select_fields' => 'beautiful#select_fields'\n"
180
+ route(myroute)
181
+ end
182
+
156
183
  myroute = ""
157
184
  myroute += "namespace :#{namespace_alone} do\n " if not namespace_alone.blank?
158
185
  myroute += "resources :#{model_pluralize} do\n collection do\n post :batch\n end\n end\n"
@@ -1,80 +1,56 @@
1
1
  $(document).ready(function(){
2
2
 
3
- /* Menu */
4
- $(".menuelt").click(function(){
5
- $(".menuelt").removeClass("active");
6
- $(this).addClass("active");
7
-
8
- idsubmenu = $(this).attr('data-id');
9
- $(".submenu").addClass("hidden");
10
- $("#"+idsubmenu).removeClass("hidden");
11
- });
12
-
13
- /* Box */
14
- $(".box-title").click(function(){
15
- p = $(this).parent();
16
- if(p.hasClass("close")){
17
- p.removeClass("close",500)
18
- }else{
19
- p.addClass("close",500)
20
- }
21
- });
22
-
23
- /* Flash */
24
- $("#flash-warning,#flash-notice,#flash-success,#flash-error").click(function(){
25
- $(this).fadeOut(1000, function(){
26
- $(this).remove();
3
+ /* Richtext editor */
4
+ $('.select-richtext').click(function(){
5
+ $('.label-richtext-type[for=' + $(this).attr('id') + ']').trigger('click');
6
+ });
7
+ $('.label-richtext-type').live("click", function(){
8
+ elt = $('#' + $(this).attr('for'));
9
+ newSet = elt.val();
10
+ idspleditor = elt.attr('data-spleditor');
11
+ ideditor = elt.attr('data-editor');
12
+ $('#' + idspleditor).markItUpRemove();
13
+ if(!$('#' + idspleditor).hasClass('markItUpEditor')){
14
+ switch(newSet) {
15
+ case 'bbcode':
16
+ $('#' + idspleditor).markItUp(myBbcodeSettings);
17
+ break;
18
+ case 'wiki':
19
+ $('#' + idspleditor).markItUp(myWikiSettings);
20
+ break;
21
+ case 'textile':
22
+ $('#' + idspleditor).markItUp(myTextileSettings);
23
+ break;
24
+ case 'markdown':
25
+ $('#' + idspleditor).markItUp(myMarkdownSettings);
26
+ break;
27
+ case 'html':
28
+ $('#' + idspleditor).markItUp(myHtmlSettings);
29
+ break;
30
+ }
31
+ }
32
+ $('#' + ideditor).removeClass("bbcode html markdown textile wiki").addClass(newSet);
33
+ return true;
27
34
  });
28
- });
29
-
30
- /* Richtext editor */
31
- $('.select-richtext').click(function(){
32
- $('.label-richtext-type[for=' + $(this).attr('id') + ']').trigger('click');
33
- });
34
- $('.label-richtext-type').live("click", function(){
35
- elt = $('#' + $(this).attr('for'));
36
- newSet = elt.val();
37
- idspleditor = elt.attr('data-spleditor');
38
- ideditor = elt.attr('data-editor');
39
- $('#' + idspleditor).markItUpRemove();
40
- if(!$('#' + idspleditor).hasClass('markItUpEditor')){
41
- switch(newSet) {
42
- case 'bbcode':
43
- $('#' + idspleditor).markItUp(myBbcodeSettings);
44
- break;
45
- case 'wiki':
46
- $('#' + idspleditor).markItUp(myWikiSettings);
47
- break;
48
- case 'textile':
49
- $('#' + idspleditor).markItUp(myTextileSettings);
50
- break;
51
- case 'markdown':
52
- $('#' + idspleditor).markItUp(myMarkdownSettings);
53
- break;
54
- case 'html':
55
- $('#' + idspleditor).markItUp(myHtmlSettings);
56
- break;
57
- }
58
- }
59
- $('#' + ideditor).removeClass("bbcode html markdown textile wiki").addClass(newSet);
60
- return true;
61
- });
62
35
  });
63
36
 
64
37
  $(function(){
65
- try{
66
- /* PJAX initializer */
67
- $('a:not(.nopjax)').pjax('#pjax-container').live('click');
68
- $('#pjax-container').bind('pjax:start', function() {
69
- $('.loader').show();
70
- $("#flash-warning,#flash-notice,#flash-success,#flash-error").fadeOut(1000, function(){
71
- $("#flash-warning,#flash-notice,#flash-success,#flash-error").remove();
72
- });
73
- }).bind('pjax:end', function() { $('.loader').hide() })
74
- .bind('pjax:timeout', function() { $('.loader').show();return false; });
75
- }
76
- catch(err)
77
- {
78
- //Handle errors here
79
- }
38
+ try{
39
+ /* PJAX initializer */
40
+ $('a:not(.nopjax)').pjax('#pjax-container').live('click');
41
+ $('a:not(.nopjax)').live('click', function(){
42
+ /* Work on all bootstrap navbar */
43
+ $(this).parent().parent().find('.active').removeClass('active');
44
+ $(this).parent().addClass('active');
45
+ });
46
+ $('#pjax-container').bind('pjax:start', function() {
47
+ $('.loader').show();
48
+ }).bind('pjax:end', function() {
49
+ $('.loader').hide();
50
+ }).bind('pjax:timeout', function() { $('.loader').show();return false; });
51
+ }
52
+ catch(err)
53
+ {
54
+ //Handle errors here
55
+ }
80
56
  });
@@ -0,0 +1,90 @@
1
+ /* ==========================================================
2
+ * bootstrap-alert.js v2.0.4
3
+ * http://twitter.github.com/bootstrap/javascript.html#alerts
4
+ * ==========================================================
5
+ * Copyright 2012 Twitter, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ========================================================== */
19
+
20
+
21
+ !function ($) {
22
+
23
+ "use strict"; // jshint ;_;
24
+
25
+
26
+ /* ALERT CLASS DEFINITION
27
+ * ====================== */
28
+
29
+ var dismiss = '[data-dismiss="alert"]'
30
+ , Alert = function (el) {
31
+ $(el).on('click', dismiss, this.close)
32
+ }
33
+
34
+ Alert.prototype.close = function (e) {
35
+ var $this = $(this)
36
+ , selector = $this.attr('data-target')
37
+ , $parent
38
+
39
+ if (!selector) {
40
+ selector = $this.attr('href')
41
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
42
+ }
43
+
44
+ $parent = $(selector)
45
+
46
+ e && e.preventDefault()
47
+
48
+ $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
49
+
50
+ $parent.trigger(e = $.Event('close'))
51
+
52
+ if (e.isDefaultPrevented()) return
53
+
54
+ $parent.removeClass('in')
55
+
56
+ function removeElement() {
57
+ $parent
58
+ .trigger('closed')
59
+ .remove()
60
+ }
61
+
62
+ $.support.transition && $parent.hasClass('fade') ?
63
+ $parent.on($.support.transition.end, removeElement) :
64
+ removeElement()
65
+ }
66
+
67
+
68
+ /* ALERT PLUGIN DEFINITION
69
+ * ======================= */
70
+
71
+ $.fn.alert = function (option) {
72
+ return this.each(function () {
73
+ var $this = $(this)
74
+ , data = $this.data('alert')
75
+ if (!data) $this.data('alert', (data = new Alert(this)))
76
+ if (typeof option == 'string') data[option].call($this)
77
+ })
78
+ }
79
+
80
+ $.fn.alert.Constructor = Alert
81
+
82
+
83
+ /* ALERT DATA-API
84
+ * ============== */
85
+
86
+ $(function () {
87
+ $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
88
+ })
89
+
90
+ }(window.jQuery);
@@ -0,0 +1,100 @@
1
+ /* ============================================================
2
+ * bootstrap-dropdown.js v2.0.4
3
+ * http://twitter.github.com/bootstrap/javascript.html#dropdowns
4
+ * ============================================================
5
+ * Copyright 2012 Twitter, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ * ============================================================ */
19
+
20
+
21
+ !function ($) {
22
+
23
+ "use strict"; // jshint ;_;
24
+
25
+
26
+ /* DROPDOWN CLASS DEFINITION
27
+ * ========================= */
28
+
29
+ var toggle = '[data-toggle="dropdown"]'
30
+ , Dropdown = function (element) {
31
+ var $el = $(element).on('click.dropdown.data-api', this.toggle)
32
+ $('html').on('click.dropdown.data-api', function () {
33
+ $el.parent().removeClass('open')
34
+ })
35
+ }
36
+
37
+ Dropdown.prototype = {
38
+
39
+ constructor: Dropdown
40
+
41
+ , toggle: function (e) {
42
+ var $this = $(this)
43
+ , $parent
44
+ , selector
45
+ , isActive
46
+
47
+ if ($this.is('.disabled, :disabled')) return
48
+
49
+ selector = $this.attr('data-target')
50
+
51
+ if (!selector) {
52
+ selector = $this.attr('href')
53
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
54
+ }
55
+
56
+ $parent = $(selector)
57
+ $parent.length || ($parent = $this.parent())
58
+
59
+ isActive = $parent.hasClass('open')
60
+
61
+ clearMenus()
62
+
63
+ if (!isActive) $parent.toggleClass('open')
64
+
65
+ return false
66
+ }
67
+
68
+ }
69
+
70
+ function clearMenus() {
71
+ $(toggle).parent().removeClass('open')
72
+ }
73
+
74
+
75
+ /* DROPDOWN PLUGIN DEFINITION
76
+ * ========================== */
77
+
78
+ $.fn.dropdown = function (option) {
79
+ return this.each(function () {
80
+ var $this = $(this)
81
+ , data = $this.data('dropdown')
82
+ if (!data) $this.data('dropdown', (data = new Dropdown(this)))
83
+ if (typeof option == 'string') data[option].call($this)
84
+ })
85
+ }
86
+
87
+ $.fn.dropdown.Constructor = Dropdown
88
+
89
+
90
+ /* APPLY TO STANDARD DROPDOWN ELEMENTS
91
+ * =================================== */
92
+
93
+ $(function () {
94
+ $('html').on('click.dropdown.data-api', clearMenus)
95
+ $('body')
96
+ .on('click.dropdown', '.dropdown form', function (e) { e.stopPropagation() })
97
+ .on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle)
98
+ })
99
+
100
+ }(window.jQuery);