railstrap 0.0.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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/app/helpers/railstrap/application_helper.rb +260 -0
- data/config/routes.rb +2 -0
- data/lib/generators/railstrap/crud/USAGE +8 -0
- data/lib/generators/railstrap/crud/crud_generator.rb +160 -0
- data/lib/generators/railstrap/crud/templates/controller.rb +109 -0
- data/lib/generators/railstrap/crud/templates/view_edit.html.erb +12 -0
- data/lib/generators/railstrap/crud/templates/view_form.html.erb +18 -0
- data/lib/generators/railstrap/crud/templates/view_index.html.erb +11 -0
- data/lib/generators/railstrap/crud/templates/view_new.html.erb +12 -0
- data/lib/generators/railstrap/crud/templates/view_print.html.erb +13 -0
- data/lib/generators/railstrap/crud/templates/view_show.html.erb +14 -0
- data/lib/generators/railstrap/crud/templates/view_sidebar.html.erb +13 -0
- data/lib/generators/railstrap/crud/templates/view_signin.html.erb +36 -0
- data/lib/generators/railstrap/crud/templates/view_signup.html.erb +52 -0
- data/lib/generators/railstrap/crud/templates/view_text.html.erb +18 -0
- data/lib/generators/railstrap/install/install_generator.rb +74 -0
- data/lib/generators/railstrap/kaminari/templates/_first_page.html.erb +14 -0
- data/lib/generators/railstrap/kaminari/templates/_gap.html.erb +8 -0
- data/lib/generators/railstrap/kaminari/templates/_last_page.html.erb +14 -0
- data/lib/generators/railstrap/kaminari/templates/_next_page.html.erb +13 -0
- data/lib/generators/railstrap/kaminari/templates/_page.html.erb +12 -0
- data/lib/generators/railstrap/kaminari/templates/_paginator.html.erb +25 -0
- data/lib/generators/railstrap/kaminari/templates/_prev_page.html.erb +13 -0
- data/lib/generators/railstrap/layout/layout_generator.rb +30 -0
- data/lib/generators/railstrap/layout/templates/layout_railstrap.html.erb +134 -0
- data/lib/generators/railstrap/layout/templates/railstrap_painel.css.scss.erb +284 -0
- data/lib/generators/railstrap/layout/templates/railstrap_painel.js.erb +35 -0
- data/lib/railstrap.rb +9 -0
- data/lib/railstrap/action_controller.rb +29 -0
- data/lib/railstrap/active_record.rb +8 -0
- data/lib/railstrap/active_record/search.rb +52 -0
- data/lib/railstrap/engine.rb +29 -0
- data/lib/railstrap/version.rb +3 -0
- data/lib/tasks/railstrap_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/railstrap_painel.js +35 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/railstrap_painel.css.scss +284 -0
- data/test/dummy/app/controllers/application_controller.rb +7 -0
- data/test/dummy/app/controllers/painel/authors_controller.rb +84 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/article.rb +3 -0
- data/test/dummy/app/models/author.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/painel.html.erb +135 -0
- data/test/dummy/app/views/painel/authors/_form.html.erb +20 -0
- data/test/dummy/app/views/painel/authors/edit.html.erb +12 -0
- data/test/dummy/app/views/painel/authors/index.html.erb +12 -0
- data/test/dummy/app/views/painel/authors/new.html.erb +12 -0
- data/test/dummy/app/views/painel/authors/show.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +65 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20120604170000_create_articles.rb +12 -0
- data/test/dummy/db/migrate/20120604170057_create_authors.rb +10 -0
- data/test/dummy/db/schema.rb +31 -0
- data/test/dummy/log/development.log +3278 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/articles.yml +13 -0
- data/test/dummy/test/fixtures/authors.yml +9 -0
- data/test/dummy/test/unit/article_test.rb +7 -0
- data/test/dummy/test/unit/author_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/C86/B70/sprockets%2Fcd9a89973c62604382628d4b42365c1a +0 -0
- data/test/dummy/tmp/cache/assets/CB3/120/sprockets%2F0725460776a8a901aa58b85f4cce5456 +0 -0
- data/test/dummy/tmp/cache/assets/CDD/EE0/sprockets%2F7ab399ca754638905a70e366e1c1ab33 +0 -0
- data/test/dummy/tmp/cache/assets/CE2/EE0/sprockets%2Fd78ec4726951f44cb085d0db080960e3 +0 -0
- data/test/dummy/tmp/cache/assets/D09/2B0/sprockets%2F045947e6b2bba2ff33c67b51b63734a6 +0 -0
- data/test/dummy/tmp/cache/assets/D0B/A40/sprockets%2F241cecf5326c934ab0440a7c76ad7597 +0 -0
- data/test/dummy/tmp/cache/assets/D1D/870/sprockets%2Fa9e5ee43f30c1886f8d66c413395bd63 +0 -0
- data/test/dummy/tmp/cache/assets/D2B/DD0/sprockets%2Fddc372002f3306cc0d74fea616ed1138 +0 -0
- data/test/dummy/tmp/cache/assets/D46/920/sprockets%2F8f3c0c4bf52b27a6646e49751e4e8f0c +0 -0
- data/test/dummy/tmp/cache/assets/D72/0B0/sprockets%2F56e9ec06e41d1cf9d692d674b5ddb210 +0 -0
- data/test/dummy/tmp/cache/assets/D7C/A80/sprockets%2Fd2d9ec09fb9bc7f8a0758392420e5c7d +0 -0
- data/test/dummy/tmp/cache/assets/D7D/9D0/sprockets%2F28fea8457f4a95a2c2d34a6e77df509e +0 -0
- data/test/dummy/tmp/cache/assets/D98/3C0/sprockets%2F36f548ab10ebcf8badf47d2719bb8500 +0 -0
- data/test/dummy/tmp/cache/assets/DB6/7B0/sprockets%2F120aa322daea3a2aa3667ffd6931eb9b +0 -0
- data/test/dummy/tmp/cache/assets/DCB/E50/sprockets%2F89f6b8aeb7d09c0bad5151bab92e5f42 +0 -0
- data/test/dummy/tmp/cache/assets/DCF/B50/sprockets%2F5ef130bc93784a52897bbab7bbd4c8ea +0 -0
- data/test/dummy/tmp/cache/assets/DD4/B00/sprockets%2F518e3d3f425eccc9558a03f6ddd36ced +0 -0
- data/test/dummy/tmp/cache/assets/E53/040/sprockets%2Fb7edacfada15c14fe43ea3b5fc8e2463 +0 -0
- data/test/dummy/tmp/cache/sass/0c9acd3b93b1d41708045c7041c76bbf41b2e963/_bootstrap-responsive.scssc +997 -0
- data/test/dummy/tmp/cache/sass/0c9acd3b93b1d41708045c7041c76bbf41b2e963/_bootstrap.scssc +0 -0
- data/test/dummy/tmp/cache/sass/1ea5acef392f2f8c40312d480463a71d2049b360/railstrap_painel.css.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_accordion.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_alerts.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_breadcrumbs.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_button-groups.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_buttons.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_carousel.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_close.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_code.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_component-animations.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_dropdowns.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_forms.scssc +1494 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_grid.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_hero-unit.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_labels-badges.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_layouts.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_mixins.scssc +2620 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_modals.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_navbar.scssc +1209 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_navs.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_pager.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_pagination.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_popovers.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_progress-bars.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_reset.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_scaffolding.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_sprites.scssc +1064 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_tables.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_thumbnails.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_tooltip.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_type.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_utilities.scssc +0 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_variables.scssc +684 -0
- data/test/dummy/tmp/cache/sass/9891e82674b6910cebee3910c86e2ef69e96f15b/_wells.scssc +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/railstrap_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +420 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2012 ALLAN FREITAS
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'Railstrap'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Bundler::GemHelper.install_tasks
|
|
29
|
+
|
|
30
|
+
require 'rake/testtask'
|
|
31
|
+
|
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
|
33
|
+
t.libs << 'lib'
|
|
34
|
+
t.libs << 'test'
|
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
|
36
|
+
t.verbose = false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
task :default => :test
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
module Railstrap
|
|
2
|
+
module ApplicationHelper
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
##### HELPERS PARA TABLE #############
|
|
6
|
+
|
|
7
|
+
#TABLE
|
|
8
|
+
def tb_table_for(collection, *args, &proc)
|
|
9
|
+
options = args.extract_options!
|
|
10
|
+
options[:html]={:class=>'table table-striped table-bordered table-condensed'}
|
|
11
|
+
table_for collection, options do |t|
|
|
12
|
+
if options[:actions].present? && options[:actions].count > 0
|
|
13
|
+
t.column :title=>"",:html => { :th => { :width => ((options[:actions].count.to_i*21)).to_s }, :td=>{:class=>"btn_actions"}} do |resource|
|
|
14
|
+
options[:actions].each do |action|
|
|
15
|
+
p resource.class
|
|
16
|
+
if [:show,:edit,:delete].include? action
|
|
17
|
+
concat(send("table_btn_#{action}",resource))
|
|
18
|
+
elsif [:select].include? action
|
|
19
|
+
concat(send("table_btn_show",resource,params[:fill]))
|
|
20
|
+
else
|
|
21
|
+
concat(send("#{action}",resource))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
begin
|
|
27
|
+
t.instance_eval(&proc)
|
|
28
|
+
rescue
|
|
29
|
+
concat("")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
#BOTAO GENERICO
|
|
36
|
+
def table_button_generic(button,icon,path,*args)
|
|
37
|
+
options = args.extract_options!
|
|
38
|
+
|
|
39
|
+
options[:class] = "btn btn-smallest btn-"+button
|
|
40
|
+
|
|
41
|
+
#concat(link_to content_tag("i", "",:class=>"icon-"+icon+" icon-white"), path, options)
|
|
42
|
+
link_to content_tag("i", "",:class=>"icon-"+icon+" icon-white"), path, options
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def table_btn_show(model, *args)
|
|
47
|
+
options = args.extract_options!
|
|
48
|
+
|
|
49
|
+
model_name = model.class.to_s.underscore
|
|
50
|
+
|
|
51
|
+
name_space_controller = ''
|
|
52
|
+
if !@namespace.nil?
|
|
53
|
+
name_space_controller << @namespace << '_'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
table_button_generic('info', 'search', send("#{name_space_controller}#{model_name}_path",model), options)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def table_btn_edit(model, *args)
|
|
60
|
+
model_name = model.class.to_s.underscore
|
|
61
|
+
|
|
62
|
+
options = args.extract_options!
|
|
63
|
+
|
|
64
|
+
name_space_controller = ''
|
|
65
|
+
if !@namespace.nil?
|
|
66
|
+
name_space_controller << @namespace << '_'
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
table_button_generic('warning', 'pencil', send("edit_#{name_space_controller}#{model_name}_path",model), options)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def table_btn_delete(model, *args)
|
|
74
|
+
options = args.extract_options!
|
|
75
|
+
|
|
76
|
+
model_name = model.class.to_s.underscore
|
|
77
|
+
|
|
78
|
+
options[:confirm] = 'Deletar! Você tem certeza?'
|
|
79
|
+
options[:method] = :delete
|
|
80
|
+
|
|
81
|
+
name_space_controller = ''
|
|
82
|
+
if !@namespace.nil?
|
|
83
|
+
name_space_controller << @namespace << '_'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
table_button_generic('danger', 'minus', send("#{name_space_controller}#{model_name}_path",model), options)
|
|
87
|
+
end
|
|
88
|
+
#####################################
|
|
89
|
+
|
|
90
|
+
#
|
|
91
|
+
def tb_fixed_toolbar(title="",path="",&block)
|
|
92
|
+
#content_tag :header,:class=>"jumbotron subhead" do
|
|
93
|
+
content_tag :div, :class=>"subnav subnav-fixed" do
|
|
94
|
+
content_tag :div, :class => "container" do
|
|
95
|
+
content_tag :ul,:class=>"nav nav-pills", :id=>"overview" do
|
|
96
|
+
concat(tb_page_title(title, path))
|
|
97
|
+
block.call
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
#end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#TOP BAR HELPERS
|
|
105
|
+
def tb_page_title(title, path)
|
|
106
|
+
content_tag :li do
|
|
107
|
+
link_to(content_tag("b", title), path)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
#
|
|
111
|
+
def tb_search_tool(class_ref, nested_path = nil)
|
|
112
|
+
class_name = class_ref.name.to_s.underscore
|
|
113
|
+
|
|
114
|
+
name_space_controller = ''
|
|
115
|
+
if !@namespace.nil?
|
|
116
|
+
name_space_controller << @namespace << '_'
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
if nested_path.nil?
|
|
120
|
+
meu_path = send("#{name_space_controller}#{class_name.pluralize}_path")
|
|
121
|
+
else
|
|
122
|
+
nested_path = nested_path.name.to_s.underscore
|
|
123
|
+
|
|
124
|
+
meu_path = send("#{name_space_controller}#{nested_path}_#{class_name.pluralize}_path")
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
content_tag :li do
|
|
128
|
+
form_tag(meu_path, :method=>"get", :id=>"formsearch", :style=>"padding-top:4px;padding-left:10px;",:class=>"form-search form-search-top") do
|
|
129
|
+
#concat(hidden_field_tag :fill, params[:fill])
|
|
130
|
+
concat(text_field_tag :search, params[:search], :class=>"input-medium search-query")
|
|
131
|
+
concat(content_tag("button",:type=>"submit",:class=>"btn btn-info",:style=>"margin-left:4px;",:id=>"btn-search") do
|
|
132
|
+
content_tag("i", "",:class=>"icon-search icon-white")
|
|
133
|
+
end)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def tb_add_button_to(model, nested_path = nil)
|
|
139
|
+
model_name = model.name.to_s.underscore
|
|
140
|
+
|
|
141
|
+
name_space_controller = ''
|
|
142
|
+
if !@namespace.nil?
|
|
143
|
+
name_space_controller << @namespace << '_'
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
if nested_path.nil?
|
|
148
|
+
nested_path = ''
|
|
149
|
+
else
|
|
150
|
+
nested_path = nested_path.name.to_s.underscore << '_'
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
content_tag :li do
|
|
154
|
+
link_to content_tag("i", "",:class=>"icon-plus")<<" Adicionar", send("new_#{name_space_controller}#{nested_path}#{model_name}_path"), :id=>"add"
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def tb_cancel_button_to(model)
|
|
160
|
+
model_name = model.class.to_s.underscore
|
|
161
|
+
|
|
162
|
+
name_space_controller = ''
|
|
163
|
+
if !@namespace.nil?
|
|
164
|
+
name_space_controller << @namespace << '_'
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
content_tag :li do
|
|
168
|
+
link_to content_tag("i", "",:class=>"icon-backward")<<' Cancelar', send("#{name_space_controller}#{model_name.pluralize}_path"),:id=>"cancel"
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
#BUUTTON_HELPERS
|
|
173
|
+
def tb_edit_button_to(model)
|
|
174
|
+
model_name = model.class.to_s.underscore
|
|
175
|
+
|
|
176
|
+
name_space_controller = ''
|
|
177
|
+
if !@namespace.nil?
|
|
178
|
+
name_space_controller << @namespace << '_'
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
content_tag :li do
|
|
182
|
+
link_to content_tag("i", "",:class=>"icon-pencil")<<' Editar', send("edit_#{name_space_controller}#{model_name}_path",model)
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
#BUUTTON_HELPERS
|
|
188
|
+
def tb_delete_button_to(model)
|
|
189
|
+
|
|
190
|
+
model_name = model.class.to_s.underscore
|
|
191
|
+
|
|
192
|
+
name_space_controller = ''
|
|
193
|
+
if !@namespace.nil?
|
|
194
|
+
name_space_controller << @namespace << '_'
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
content_tag :li do
|
|
198
|
+
link_to content_tag("i", "",:class=>"icon-minus")<<' Excluir', send("#{name_space_controller}#{model_name}_path",model), :confirm => 'Deseja realmente excluir?', :method => :delete
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def tb_submit_button_to(model,text="Salvar")
|
|
203
|
+
content_tag :li do
|
|
204
|
+
tb_link_to_submit model, content_tag("i", "",:class=>"icon-ok")<<" "<<text,:id=>"submit"
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def tb_link_to_submit(model, name, html_options={})
|
|
209
|
+
class_name = model.class.to_s.underscore
|
|
210
|
+
#link_to_function name, ";$(this).closest('form').submit()",html_options
|
|
211
|
+
link_to_function name, ";$('form[id*=#{class_name}]').submit()",html_options
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
### PAGINACAO
|
|
215
|
+
def tb_paginate_navbar(resource,*args)
|
|
216
|
+
options = args.extract_options!
|
|
217
|
+
#options[:page_links] = true if options[:page_links].present?
|
|
218
|
+
#options[:previous_label] = content_tag("i"," ",:class=>"icon-arrow-left")
|
|
219
|
+
#options[:next_label] = content_tag("i"," ",:class=>"icon-arrow-right")
|
|
220
|
+
new_options = options
|
|
221
|
+
|
|
222
|
+
begin
|
|
223
|
+
flexa_wp = will_paginate resource, new_options
|
|
224
|
+
rescue
|
|
225
|
+
""
|
|
226
|
+
end
|
|
227
|
+
begin
|
|
228
|
+
flexa_wp["<ul>"]= ""
|
|
229
|
+
rescue
|
|
230
|
+
""
|
|
231
|
+
end
|
|
232
|
+
begin
|
|
233
|
+
flexa_wp["</ul>"]= ""
|
|
234
|
+
rescue
|
|
235
|
+
""
|
|
236
|
+
end
|
|
237
|
+
begin
|
|
238
|
+
flexa_wp['<div class="pagination">']= ""
|
|
239
|
+
rescue
|
|
240
|
+
""
|
|
241
|
+
end
|
|
242
|
+
begin
|
|
243
|
+
flexa_wp["</div>"]= ""
|
|
244
|
+
rescue
|
|
245
|
+
""
|
|
246
|
+
end
|
|
247
|
+
flexa_wp
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def tb_boolean_grid(status)
|
|
251
|
+
if status
|
|
252
|
+
imagem = 'icon_sucess.gif'
|
|
253
|
+
else
|
|
254
|
+
imagem = 'icon_error.gif'
|
|
255
|
+
end
|
|
256
|
+
image_tag(imagem)
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
end
|
|
260
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#crud_generator.rb
|
|
2
|
+
module Railstrap
|
|
3
|
+
class CrudGenerator < Rails::Generators::NamedBase
|
|
4
|
+
|
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
#check_class_collision :suffix => "Controller"
|
|
8
|
+
|
|
9
|
+
#argument :controller_path, :type => :string
|
|
10
|
+
argument :name, :type => :string
|
|
11
|
+
argument :model_name, :type => :string #, :required => false
|
|
12
|
+
|
|
13
|
+
class_option :no_controller, :type => :boolean, :default => false, :desc => 'Sem controller'
|
|
14
|
+
class_option :no_views, :type => :boolean, :default => false, :desc => 'Sem Views'
|
|
15
|
+
|
|
16
|
+
#ADICIONAR SUPORTE A WILL_PAGINATE DEPOIS
|
|
17
|
+
#class_option :will_paginate, :type => :boolean, :default => false, :desc => 'Specify if you use will_paginate'
|
|
18
|
+
class_option :kaminari, :type => :boolean, :default => false, :desc => 'Specify if you use Kaminari'
|
|
19
|
+
|
|
20
|
+
class_option :themed_type, :type => :string, :default => 'crud',
|
|
21
|
+
:desc => 'Specify the themed type: crud, list or show. Default is crud'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def initialize(args, *options)
|
|
25
|
+
#p args.to_yaml
|
|
26
|
+
|
|
27
|
+
super(args, *options)
|
|
28
|
+
initialize_views_variables
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def create_controller_files
|
|
33
|
+
return if options.no_controller
|
|
34
|
+
#if !options.no_controller
|
|
35
|
+
template "controller.rb", File.join('app/controllers', "#{@controller_file_path}_controller.rb")
|
|
36
|
+
|
|
37
|
+
if @controller_class_nesting_depth == 1
|
|
38
|
+
route("namespace :#{@controller_class_nesting.downcase.underscore} do
|
|
39
|
+
resources :#{plural_resource_name}
|
|
40
|
+
end")
|
|
41
|
+
else
|
|
42
|
+
route("resources :#{plural_resource_name}")
|
|
43
|
+
end
|
|
44
|
+
#end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def copy_views
|
|
48
|
+
generate_views
|
|
49
|
+
#unless options.layout.blank?
|
|
50
|
+
#if options.engine =~ /erb/
|
|
51
|
+
#gsub_file(File.join('app/views/layouts', "#{options[:layout]}.html.#{options.engine}"), /\<div\s+id=\"main-navigation\">.*\<\/ul\>/mi) do |match|
|
|
52
|
+
# match.gsub!(/\<\/ul\>/, "")
|
|
53
|
+
# %|#{match} <li class="<%= controller.controller_path == '#{@controller_file_path}' ? 'active' : '' %>"><a href="<%= #{controller_routing_path}_path %>">#{plural_model_name}</a></li></ul>|
|
|
54
|
+
#end
|
|
55
|
+
#end
|
|
56
|
+
#end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
protected
|
|
60
|
+
|
|
61
|
+
def initialize_views_variables
|
|
62
|
+
#@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
|
|
63
|
+
@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(name)
|
|
64
|
+
@controller_routing_path = @controller_file_path.gsub(/\//, '_')
|
|
65
|
+
@model_name = @base_name.singularize unless @model_name
|
|
66
|
+
@model_name = @model_name.camelize
|
|
67
|
+
|
|
68
|
+
#p "#################################"
|
|
69
|
+
#p extract_modules(name)
|
|
70
|
+
#p "#################################"
|
|
71
|
+
#abort("PAREI")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def controller_routing_path
|
|
75
|
+
@controller_routing_path
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def singular_controller_routing_path
|
|
79
|
+
@controller_routing_path.singularize
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def model_name
|
|
83
|
+
@model_name
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def plural_model_name
|
|
87
|
+
@model_name.pluralize
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def resource_name
|
|
91
|
+
@model_name.underscore
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def plural_resource_name
|
|
95
|
+
resource_name.pluralize
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#
|
|
99
|
+
def namespace_path
|
|
100
|
+
if @controller_class_nesting_depth == 0
|
|
101
|
+
''
|
|
102
|
+
else
|
|
103
|
+
@controller_class_nesting.downcase+'_'
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
##
|
|
108
|
+
# Attempts to call #columns on the model's class
|
|
109
|
+
# If the (Active Record) #columns method does not exist, it attempts to
|
|
110
|
+
# perform the (Mongoid) #fields method instead
|
|
111
|
+
def columns
|
|
112
|
+
begin
|
|
113
|
+
excluded_column_names = %w[id created_at updated_at]
|
|
114
|
+
Kernel.const_get(@model_name).columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
|
|
115
|
+
rescue NoMethodError
|
|
116
|
+
Kernel.const_get(@model_name).fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def extract_modules(name)
|
|
121
|
+
modules = name.include?('/') ? name.split('/') : name.split('::')
|
|
122
|
+
name = modules.pop
|
|
123
|
+
path = modules.map { |m| m.underscore }
|
|
124
|
+
file_path = (path + [name.underscore]).join('/')
|
|
125
|
+
nesting = modules.map { |m| m.camelize }.join('::')
|
|
126
|
+
[name, path, file_path, nesting, modules.size]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def generate_views
|
|
130
|
+
return if options.no_views
|
|
131
|
+
|
|
132
|
+
views = {
|
|
133
|
+
'crud' => {
|
|
134
|
+
'view_index.html.erb' => File.join('app/views', @controller_file_path, "index.html.erb"),
|
|
135
|
+
'view_new.html.erb' => File.join('app/views', @controller_file_path, "new.html.erb"),
|
|
136
|
+
'view_edit.html.erb' => File.join('app/views', @controller_file_path, "edit.html.erb"),
|
|
137
|
+
'view_form.html.erb' => File.join('app/views', @controller_file_path, "_form.html.erb"),
|
|
138
|
+
'view_show.html.erb' => File.join('app/views', @controller_file_path, "show.html.erb")
|
|
139
|
+
},
|
|
140
|
+
'list' => {
|
|
141
|
+
'view_index.html.erb' => File.join('app/views', @controller_file_path, "index.html.erb")
|
|
142
|
+
},
|
|
143
|
+
'show' => {
|
|
144
|
+
'view_show.html.erb' => File.join('app/views', @controller_file_path, "show.html.erb")
|
|
145
|
+
#'view_sidebar.html.erb' => File.join('app/views', @controller_file_path, "_sidebar.html.#{options.engine}")
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
selected_views = views[options.themed_type]
|
|
149
|
+
options.engine == 'haml' ? generate_haml_views(selected_views) : generate_erb_views(selected_views)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def generate_erb_views(views)
|
|
153
|
+
views.each do |template_name, output_path|
|
|
154
|
+
template template_name, output_path
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
end#fim da class CrudGenerator
|
|
160
|
+
end#fim do modulo Railstrap
|