flexi_generators 0.3.0 → 0.3.1

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 (24) hide show
  1. data/README.md +46 -3
  2. data/flexi_generators.gemspec +2 -0
  3. data/lib/generators/flexi/config/config_generator.rb +1 -0
  4. data/lib/generators/flexi/config/templates/field_error.rb +11 -6
  5. data/lib/generators/flexi/install/install_generator.rb +3 -3
  6. data/lib/generators/flexi/install/templates/application.css +2 -2
  7. data/lib/generators/flexi/install/templates/application.js +1 -1
  8. data/lib/generators/flexi/layout/templates/_search.html.erb +3 -0
  9. data/lib/generators/flexi/layout/templates/application.css +2 -2
  10. data/lib/generators/flexi/layout/templates/layout.css +11 -1
  11. data/lib/generators/flexi/layout/templates/layout.html.erb +2 -1
  12. data/lib/generators/flexi/layout/templates/layout_helper.rb +2 -2
  13. data/lib/generators/flexi/scaffold/scaffold_generator.rb +9 -0
  14. data/lib/generators/flexi/scaffold/templates/controller.rb +45 -0
  15. data/lib/version.rb +1 -1
  16. data/vendor/assets/images/{glyphicons-halflings-white.png → flexi/glyphicons-halflings-white.png} +0 -0
  17. data/vendor/assets/images/{glyphicons-halflings.png → flexi/glyphicons-halflings.png} +0 -0
  18. data/vendor/assets/javascripts/{bootstrap.js → flexi/bootstrap.js} +1824 -1824
  19. data/vendor/assets/javascripts/flexi/bootstrap.min.js +6 -0
  20. data/vendor/assets/stylesheets/{bootstrap-responsive.css → flexi/bootstrap-responsive.css} +815 -815
  21. data/vendor/assets/stylesheets/flexi/bootstrap-responsive.min.css +9 -0
  22. data/vendor/assets/stylesheets/{bootstrap.css → flexi/bootstrap.css} +4983 -4983
  23. data/vendor/assets/stylesheets/flexi/bootstrap.min.css +9 -0
  24. metadata +65 -47
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Flexi Generators
2
2
 
3
- TODO: Write a gem description
3
+ Rails generators scripts for scaffolding and layout files containing Twitter’s Bootstrap CSS.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,10 +16,43 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install flexi_generators
18
18
 
19
- ## Usage
19
+ ## Quickstart
20
20
 
21
- TODO: Write usage instructions here
21
+ You can run following generators to get started.
22
22
 
23
+ Install (requires directives to Asset pipeline)
24
+
25
+ Usage:
26
+
27
+ $ rails g flexi:install
28
+
29
+ Config (My extra configuration files: field error, pagination, locale and inflector)
30
+
31
+ Usage:
32
+
33
+ $ rails g flexi:config
34
+
35
+ Layout (generates Twitter Bootstrap compatible layout)
36
+
37
+ Usage:
38
+
39
+ $ rails g flexi:layout
40
+
41
+ Example:
42
+
43
+ $ rails g flexi:layout application fixed
44
+
45
+ Scaffold (generates Twitter Bootstrap compatible scaffold views)
46
+
47
+ Usage:
48
+
49
+ $ rails g flexi:scaffold NAME [field[:type][:index] field[:type][:index]] [options]
50
+
51
+ Example:
52
+
53
+ $ rails g flexi:scaffold Post title description:text
54
+ rake db:migrate
55
+
23
56
  ## Contributing
24
57
 
25
58
  1. Fork it
@@ -27,3 +60,13 @@ TODO: Write usage instructions here
27
60
  3. Commit your changes (`git commit -am 'Added some feature'`)
28
61
  4. Push to the branch (`git push origin my-new-feature`)
29
62
  5. Create new Pull Request
63
+
64
+ ## Autor
65
+
66
+ Leandro de Oliveira
67
+
68
+ Blog: [http://leandroo.com.br](http://leandroo.com.br)
69
+
70
+ Github: [http://github.com/leandroo](http://github.com/leandroo)
71
+
72
+ Copyright (c) 2012 Leandro de Oliveira, released under the MIT license
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "flexi_generators"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = FlexiGenerators::VERSION
17
+ gem.add_dependency("nokogiri")
18
+ gem.add_dependency("will_paginate", "~> 3.0")
17
19
  end
@@ -18,6 +18,7 @@ module Flexi
18
18
  inject_into_class "config/application.rb", "Application","\tconfig.time_zone = 'Brasilia'\n"
19
19
 
20
20
  gem 'will_paginate', '~> 3.0'
21
+ gem 'nokogiri'
21
22
  end
22
23
 
23
24
  end
@@ -1,9 +1,14 @@
1
1
  ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
2
- if html_tag =~ /<(input|textarea|select)/
3
- %|<div class="control-group error">#{html_tag} <span class="help-inline">#{[instance.error_message].join(', ')}</span></div>|.html_safe
4
- elsif html_tag =~ /<label/
5
- %|<div class="control-group error">#{html_tag}|.html_safe
6
- else
7
- html_tag
2
+ html = html_tag.html_safe
3
+ elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input, select, textarea"
4
+ elements.each do |e|
5
+ if e.node_name.eql? 'label'
6
+ e['class'] = 'control-label error'
7
+ html = %(#{e}).html_safe
8
+ else
9
+ e['class'] = "#{e['class']} error"
10
+ html = %(#{e}).html_safe
11
+ end
8
12
  end
13
+ html
9
14
  end
@@ -8,8 +8,8 @@ module Flexi
8
8
 
9
9
  def add_stylesheets
10
10
  if File.exist?('app/assets/stylesheets/application.css')
11
- insert_into_file "app/assets/stylesheets/application.css", " *= require bootstrap-responsive\n", :after => "require_self\n"
12
- insert_into_file "app/assets/stylesheets/application.css", " *= require bootstrap\n", :after => "require_self\n"
11
+ insert_into_file "app/assets/stylesheets/application.css", " *= require flexi/bootstrap-responsive\n", :after => "require_self\n"
12
+ insert_into_file "app/assets/stylesheets/application.css", " *= require flexi/bootstrap\n", :after => "require_self\n"
13
13
  else
14
14
  copy_file "application.css", "app/assets/stylesheets/application.css"
15
15
  end
@@ -17,7 +17,7 @@ module Flexi
17
17
 
18
18
  def add_javascripts
19
19
  if File.exist?('app/assets/javascripts/application.js')
20
- insert_into_file "app/assets/javascripts/application.js", "//= require bootstrap\n", :after => "jquery_ujs\n"
20
+ insert_into_file "app/assets/javascripts/application.js", "//= require flexi/bootstrap\n", :after => "jquery_ujs\n"
21
21
  else
22
22
  copy_file "application.js", "app/assets/javascripts/application.js"
23
23
  end
@@ -9,7 +9,7 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require_self
12
- *= require bootstrap
13
- *= require bootstrap-responsive
12
+ *= require flexi/bootstrap
13
+ *= require flexi/bootstrap-responsive
14
14
  *= require_tree .
15
15
  */
@@ -12,5 +12,5 @@
12
12
  //
13
13
  //= require jquery
14
14
  //= require jquery_ujs
15
- //= require bootstrap
15
+ //= require flexi/bootstrap
16
16
  //= require_tree .
@@ -0,0 +1,3 @@
1
+ <div class="input-prepend">
2
+ <span class="add-on"><i class="icon-search"></i></span><input type="text" size="16" id="prependedInput" class="span2">
3
+ </div>
@@ -9,8 +9,8 @@
9
9
  * compiled file, but it's generally better to create a new file per style scope.
10
10
  *
11
11
  *= require_self
12
- *= require bootstrap
13
- *= require bootstrap-responsive
12
+ *= require flexi/bootstrap
13
+ *= require flexi/bootstrap-responsive
14
14
  *= require layout
15
15
  *= require_tree .
16
16
  */
@@ -5,4 +5,14 @@ fieldset legend{margin-bottom:0;}
5
5
  .sidebar-nav{padding:9px 0;}
6
6
  .navbar .brand{color:#FFFFFF !important;}
7
7
  .page-header{padding-bottom:0px !important;}
8
- .actions{text-align:center !important;}
8
+ .actions{text-align:center !important;width:15%}
9
+ /* error fields */
10
+ .control-label.error {color: #b94a48;}
11
+ .control-group input.error,
12
+ .control-group select.error,
13
+ .control-group textarea.error { color: #b94a48; border-color: #b94a48; }
14
+ .control-group input.error:focus,
15
+ .control-group select.error:focus,
16
+ .control-group textarea.error:focus {border-color: #953b39; -webkit-box-shadow: 0 0 6px #d59392; -moz-box-shadow: 0 0 6px #d59392; box-shadow: 0 0 6px #d59392;}
17
+ .control-group .error .input-prepend .add-on,
18
+ .control-group .error .input-append .add-on {color: #b94a48;background-color: #f2dede; border-color: #b94a48;}
@@ -9,7 +9,7 @@
9
9
  <meta name="author" content="">
10
10
  <%%= csrf_meta_tags %>
11
11
  <%%= stylesheet "application", :media => "all" %>
12
- <%%= yield(:head) %>
12
+ <%%= yield(:stylesheet) %>
13
13
  <!--[if lt IE 9]>
14
14
  <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
15
15
  <![endif]-->
@@ -72,5 +72,6 @@
72
72
  </div><!--/.fluid-container-->
73
73
 
74
74
  <%%= javascript_include_tag "application" %>
75
+ <%%= yield(:javascript) %>
75
76
  </body>
76
77
  </html>
@@ -13,11 +13,11 @@ module LayoutHelper
13
13
  end
14
14
 
15
15
  def stylesheet(*args)
16
- content_for(:head) { stylesheet_link_tag(*args) }
16
+ content_for(:stylesheet) { stylesheet_link_tag(*args) }
17
17
  end
18
18
 
19
19
  def javascript(*args)
20
- content_for(:head) { javascript_include_tag(*args) }
20
+ content_for(:javascript) { javascript_include_tag(*args) }
21
21
  end
22
22
 
23
23
  def menu(name, path)
@@ -1,5 +1,6 @@
1
1
  require 'rails/generators/rails/scaffold/scaffold_generator'
2
2
  require 'rails/generators/erb/scaffold/scaffold_generator'
3
+ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
3
4
 
4
5
  module Flexi
5
6
  module Generators
@@ -22,4 +23,12 @@ module Erb
22
23
  source_root File.expand_path("../templates", __FILE__)
23
24
  end
24
25
  end
26
+ end
27
+
28
+ module Rails
29
+ module Generators
30
+ class ScaffoldControllerGenerator
31
+ source_root File.expand_path("../templates", __FILE__)
32
+ end
33
+ end
25
34
  end
@@ -0,0 +1,45 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+ <% end -%>
4
+ <% module_namespacing do -%>
5
+ class <%= controller_class_name %>Controller < ApplicationController
6
+ respond_to :html, :json
7
+
8
+ def index
9
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
10
+ respond_with(@<%= plural_table_name %>)
11
+ end
12
+
13
+ def show
14
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
15
+ respond_with(@<%= singular_table_name %>)
16
+ end
17
+
18
+ def new
19
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
20
+ respond_with(@<%= singular_table_name %>)
21
+ end
22
+
23
+ def edit
24
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
25
+ end
26
+
27
+ def create
28
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "params[:#{singular_table_name}]") %>
29
+ flash[:notice] = <%= "'#{human_name} was successfully created.'" %> if @<%= orm_instance.save %>
30
+ respond_with(@<%= singular_table_name %>)
31
+ end
32
+
33
+ def update
34
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
35
+ flash[:notice] = <%= "'#{human_name} was successfully updated.'" %> if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
36
+ respond_with(@<%= singular_table_name %>)
37
+ end
38
+
39
+ def destroy
40
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
41
+ @<%= orm_instance.destroy %>
42
+ respond_with(@<%= singular_table_name %>)
43
+ end
44
+ end
45
+ <% end -%>
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module FlexiGenerators
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end