tb_core 1.2.8 → 1.3.0.beta1

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/admin/core/application.js +1 -2
  3. data/app/assets/javascripts/admin/core/dashboard.js +1 -1
  4. data/app/assets/javascripts/admin/core/modal.js +4 -13
  5. data/app/assets/javascripts/admin/core/users.js +0 -120
  6. data/app/assets/stylesheets/admin/core/application.css.scss +106 -367
  7. data/app/assets/stylesheets/admin/core/login.css.scss +3 -29
  8. data/app/controllers/admin/application_controller.rb +1 -2
  9. data/app/controllers/admin/user_sessions_controller.rb +0 -3
  10. data/app/controllers/admin/users_controller.rb +3 -13
  11. data/app/controllers/password_resets_controller.rb +1 -0
  12. data/app/controllers/spud/application_controller.rb +8 -14
  13. data/app/controllers/user_sessions_controller.rb +1 -0
  14. data/app/helpers/admin/application_helper.rb +11 -15
  15. data/app/helpers/twice_baked/application_helper.rb +24 -1
  16. data/app/models/spud/spud_user_model.rb +7 -0
  17. data/app/views/admin/dashboard/index.html.erb +2 -4
  18. data/app/views/admin/password_resets/index.html.erb +4 -4
  19. data/app/views/admin/password_resets/show.html.erb +10 -9
  20. data/app/views/admin/roles/_form.html.erb +20 -22
  21. data/app/views/admin/roles/index.html.erb +23 -21
  22. data/app/views/admin/settings/_form.html.erb +36 -45
  23. data/app/views/admin/settings/edit.html.erb +1 -1
  24. data/app/views/admin/setup/new.html.erb +37 -46
  25. data/app/views/admin/user_sessions/new.html.erb +15 -12
  26. data/app/views/admin/users/_form.html.erb +16 -86
  27. data/app/views/admin/users/edit.html.erb +1 -1
  28. data/app/views/admin/users/index.html.erb +47 -27
  29. data/app/views/admin/users/new.html.erb +1 -1
  30. data/app/views/admin/users/show.html.erb +21 -31
  31. data/app/views/layouts/admin/_flashes.html.erb +19 -0
  32. data/app/views/layouts/admin/application.html.erb +39 -48
  33. data/app/views/layouts/admin/detail.html.erb +16 -30
  34. data/app/views/layouts/admin/error_page.html.erb +2 -1
  35. data/app/views/layouts/admin/login.html.erb +4 -11
  36. data/app/views/layouts/user_sessions.html.erb +6 -0
  37. data/app/views/password_resets/index.html.erb +4 -4
  38. data/app/views/password_resets/show.html.erb +7 -7
  39. data/app/views/user_sessions/new.html.erb +6 -6
  40. data/config/locales/en.yml +10 -0
  41. data/lib/generators/spud/module_generator.rb +6 -4
  42. data/lib/generators/spud/setup_generator.rb +7 -39
  43. data/lib/generators/spud/templates/assets/application.css.scss +5 -0
  44. data/lib/generators/spud/templates/assets/application.js +1 -0
  45. data/lib/generators/spud/templates/views/admin/_form.html.erb +7 -18
  46. data/lib/generators/spud/templates/views/admin/index.html.erb +39 -28
  47. data/lib/generators/spud/templates/views/admin/show.html.erb +6 -7
  48. data/lib/generators/spud/templates/views/frontend/index.html.erb +2 -1
  49. data/lib/generators/spud/templates/views/frontend/show.html.erb +6 -4
  50. data/lib/generators/spud/templates/views/layouts/application.html.erb +16 -6
  51. data/lib/spud_core/configuration.rb +1 -1
  52. data/lib/spud_core/engine.rb +9 -1
  53. data/lib/spud_core/version.rb +1 -1
  54. data/lib/tb_core/form_builder.rb +254 -0
  55. data/spec/helpers/spud/admin/application_helper_spec.rb +5 -5
  56. metadata +38 -14
  57. data/app/assets/javascripts/admin/core/split_pane.js +0 -150
  58. data/app/assets/libs/bootstrap/css/bootstrap-responsive.css +0 -1088
  59. data/app/assets/libs/bootstrap/css/bootstrap.css.scss +0 -5893
  60. data/app/assets/libs/bootstrap/img/glyphicons-halflings-white.png +0 -0
  61. data/app/assets/libs/bootstrap/img/glyphicons-halflings.png +0 -0
  62. data/app/assets/libs/bootstrap/js/bootstrap.js +0 -2025
  63. data/app/assets/stylesheets/admin/core/roles.css +0 -4
  64. data/app/assets/stylesheets/admin/core/split_pane.css.scss +0 -126
  65. data/app/assets/stylesheets/admin/core/users.css.scss +0 -9
@@ -3,19 +3,23 @@ class Spud::SetupGenerator < ::Rails::Generators::Base
3
3
  source_root File.expand_path('../templates', __FILE__)
4
4
 
5
5
  def setup
6
+ if ask('NOTICE: Setup will now attempt to delete and/or overwrite existing files. Continue?', :limited_to => ['y', 'n']) == 'n'
7
+ return
8
+ end
9
+
6
10
  template "views/layouts/application.html.erb", "app/views/layouts/application.html.erb"
7
11
  template "application_controller.rb", "app/controllers/application_controller.rb"
8
12
  template 'assets/admin.css.scss', 'app/assets/stylesheets/admin/application.css.scss'
9
13
 
10
- update_base_stylesheet()
11
-
14
+ remove_file 'app/assets/stylesheets/application.css'
15
+ template 'assets/application.css.scss', 'app/assets/stylesheets/application.css.scss'
12
16
  template 'assets/application.js', 'app/assets/javascripts/application.js'
13
17
  template 'assets/admin/application.js', 'app/assets/javascripts/admin/application.js'
14
18
 
15
19
  environment(spud_core_configs())
16
20
  rake('railties:install:migrations')
17
21
 
18
- if ask("Migrate the database? [Yn] ").downcase == 'y'
22
+ if ask("Migrate the database?", :limited_to => ['y', 'n']).downcase == 'y'
19
23
  rake('db:migrate')
20
24
  end
21
25
  end
@@ -33,42 +37,6 @@ Spud::Core.configure do |config|
33
37
  EOF
34
38
  end
35
39
 
36
- def update_base_stylesheet()
37
- extensions = ['css', 'css.scss']
38
- extensions.each do |ext|
39
- path = File.join(Rails.root, "app/assets/stylesheets/application.#{ext}")
40
- if File.exist?(path)
41
- replace_with_require_directory(path)
42
- return
43
- end
44
- end
45
- end
46
-
47
- def update_base_javascript()
48
- extensions = ['js', 'js.coffee']
49
- extensions.each do |ext|
50
- path = File.join(Rails.root, "app/assets/javascripts/application.#{ext}")
51
- if File.exist?(path)
52
- replace_with_require_directory(path)
53
- remove_turbolinks(path)
54
- return
55
- end
56
- end
57
- end
58
-
59
- def replace_with_require_directory(path)
60
- text = File.read(path)
61
- text.gsub!('require_tree', 'require_directory')
62
- File.open(path, 'w'){ |f| f.puts(text) }
63
- end
64
-
65
- def remove_turbolinks(path)
66
- text = File.read(path)
67
- require_turbolinks = "//= require turbolinks\n"
68
- text.gsub!(require_turbolinks, '')
69
- File.open(path, 'w'){ |f| f.puts(text) }
70
- end
71
-
72
40
  def application_name
73
41
  Rails.application.class.name.split('::').first.underscore
74
42
  end
@@ -0,0 +1,5 @@
1
+ //= require_self
2
+ //= require_directory .
3
+
4
+ @import "bootstrap-sprockets";
5
+ @import "bootstrap";
@@ -1,6 +1,7 @@
1
1
  //= require jquery
2
2
  //= require jquery_ujs
3
3
  //= require tb_core
4
+ //= require bootstrap-sprockets
4
5
  //= require_self
5
6
  //= require_directory .
6
7
 
@@ -1,21 +1,10 @@
1
- <%%= form_for [:admin, @<%=module_name_formatted.singularize%>], :html => {:class => 'form-horizontal'} do |f| %>
2
-
3
- <%%= error_messages_for(f.object) %>
4
-
5
- <fieldset>
6
- <legend>Details</legend> <%attributes.each do |attribute|%>
7
- <%attribute_args = attribute.split(":")%>
8
- <div class="control-group">
9
- <%%= f.label :<%=attribute_args[0]%>, :class => "control-label" %>
10
- <div class="controls">
11
- <%= field_for_attribute(attribute_args[1], attribute_args[0]) %>
12
- </div>
13
- </div> <%end%>
14
- </fieldset>
15
-
16
- <div class="form-actions">
17
- <%%= f.submit "Save <%=module_name_formatted.singularize.humanize.titlecase%>", :class => "btn btn-primary form-btn", "data-loading-text" => "Saving..." %> or <%%= link_to "Cancel", admin_<%= module_name_formatted %>_path, :class => "btn" %>
18
- </div>
1
+ <%%= form_for [:admin, @<%=module_name_formatted.singularize%>], :builder => TbCore::FormBuilder, :html => {:class => 'form-horizontal'} do |f| %>
2
+
3
+ <%%= tb_form_error_header(f.object) %>
4
+ <%- attributes.collect{ |att| att.split(':') }.each do |arg_0, arg_1| %>
5
+ <%= field_for_attribute(arg_1, arg_0) %>
6
+ <%- end %>
7
+ <%%= f.tb_save_buttons('<%= module_name_formatted.singularize.humanize.titlecase %>', @<%= module_name_formatted.singularize %>.new_record? ? admin_<%= module_name_formatted %>_path : admin_<%= module_name_formatted.singularize %>_path(@<%= module_name_formatted.singularize %>)) %>
19
8
 
20
9
  <%% end %>
21
10
 
@@ -1,37 +1,48 @@
1
1
  <%% content_for :data_controls do %>
2
- <%%= form_tag admin_<%= module_name_formatted %>_path, :method => :get, :class => 'form-search' do %>
3
- <%%= text_field_tag 'search', params[:search], :placeholder => 'Search', :class => 'input-medium search-query' %>
2
+ <%%= form_tag admin_<%= module_name_formatted %>_path, :method => :get, :class => 'form-inline' do %>
3
+ <div class="form-group">
4
+ <div class="input-group">
5
+ <div class="input-group-addon"><span class="glyphicon glyphicon-search"></span></div>
6
+ <%%= text_field_tag 'search', params[:search], :placeholder => 'Search', :class => 'form-control' %>
7
+ <%% if params[:search] %>
8
+ <div class="input-group-addon">
9
+ <%%= link_to raw('<span class="glyphicon glyphicon-remove"></span>'), admin_<%= module_name_formatted %>_path %>
10
+ </div>
11
+ <%% end %>
12
+ </div>
13
+ </div>
14
+ <div class="form-group">
15
+ <%%= link_to "New <%=module_name_formatted.singularize.humanize.titlecase%>", new_admin_<%=module_name_formatted.singularize%>_path, :class => "btn btn-primary", :title => "New <%=module_name_formatted.singularize.humanize.titlecase%>" %>
16
+ </div>
4
17
  <%% end %>
5
- <%% if params[:search] %>
6
- <%%= link_to 'Clear', admin_<%= module_name_formatted %>_path, :class => 'btn' %>
7
- <%% end %>
8
- <%%= link_to "New <%=module_name_formatted.singularize.humanize.titlecase%>", new_admin_<%=module_name_formatted.singularize%>_path, :class => "btn btn-primary", :title => "New <%=module_name_formatted.singularize.humanize.titlecase%>" %>
9
18
  <%% end %>
10
19
 
11
20
  <%% content_for :detail do %>
12
- <table class="table table-striped">
13
- <thead>
14
- <tr><%attribute_names.each do |attribute|%>
15
- <th><%=attribute.humanize.titlecase%></th><% end %>
16
- <th>Actions</th>
17
- </tr>
18
- </thead>
19
- <tbody>
20
- <%% @<%=module_name_formatted%>.each do |<%=module_name_formatted.singularize%>| %>
21
- <tr>
22
- <%-attribute_names.each do |attribute|-%>
23
- <td><%%= <%=module_name_formatted.singularize%>.<%=attribute%> %></td>
24
- <%-end-%>
25
- <td align="right" width="150" class="no-wrap">
26
- <%%= link_to 'Details', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-mini' %>
27
- <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-mini' %>
28
- <%%= link_to 'Delete', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :method => :delete, :data => {:confirm => 'Are you sure you want to delete this <%=module_name_formatted.singularize.humanize%>?'}, :class => 'btn btn-danger btn-mini' %>
29
- </td>
21
+ <div class="table-responsive">
22
+ <table class="table table-striped table-hover">
23
+ <thead>
24
+ <tr><%attribute_names.each do |attribute|%>
25
+ <th><%=attribute.humanize.titlecase%></th><% end %>
26
+ <th>&nbsp;</th>
30
27
  </tr>
31
- <%% end %>
32
- </tbody>
33
- </table>
34
- <%%= will_paginate @<%=module_name_formatted%> %>
28
+ </thead>
29
+ <tbody>
30
+ <%% @<%=module_name_formatted%>.each do |<%=module_name_formatted.singularize%>| %>
31
+ <tr>
32
+ <%-attribute_names.each do |attribute|-%>
33
+ <td><%%= <%=module_name_formatted.singularize%>.<%=attribute%> %></td>
34
+ <%-end-%>
35
+ <td class="table-actions">
36
+ <%%= link_to 'Details', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-default btn-sm' %>
37
+ <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :class => 'btn btn-default btn-sm' %>
38
+ <%%= link_to 'Delete', admin_<%=module_name_formatted.singularize%>_path(<%=module_name_formatted.singularize%>), :method => :delete, :data => {:confirm => 'Are you sure you want to delete this <%=module_name_formatted.singularize.humanize%>?'}, :class => 'btn btn-danger btn-sm' %>
39
+ </td>
40
+ </tr>
41
+ <%% end %>
42
+ </tbody>
43
+ </table>
44
+ </div>
45
+ <%%= will_paginate @<%=module_name_formatted%>, :renderer => BootstrapPagination::Rails %>
35
46
 
36
47
  <script>
37
48
  $(document).ready(app.admin.<%= module_name_formatted %>.index);
@@ -1,16 +1,15 @@
1
1
  <%% content_for :data_controls do %>
2
- <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(@<%=module_name_formatted.singularize%>), :class => 'btn' %>
2
+ <%%= link_to 'Edit', edit_admin_<%=module_name_formatted.singularize%>_path(@<%=module_name_formatted.singularize%>), :class => 'btn btn-default' %>
3
3
  <%% end %>
4
4
 
5
- <ul>
5
+ <dl class="dl-horizontal">
6
6
  <%- attribute_names.each do |attribute| -%>
7
- <li><strong><%= attribute.humanize.titlecase %>:</strong> <%%= @<%= module_name_formatted.singularize %>.<%= attribute %> %></li>
7
+ <dt><%= attribute.humanize.titlecase %>:</dt>
8
+ <dd><%%= @<%= module_name_formatted.singularize %>.<%= attribute %> %></dd>
8
9
  <%- end -%>
9
- </ul>
10
+ </dl>
10
11
 
11
- <div class="form-actions">
12
- <%%= link_to "Back", admin_<%= module_name_formatted %>_path, :class => "btn" %>
13
- </div>
12
+ <%%= link_to "Back", admin_<%= module_name_formatted %>_path, :class => "btn btn-default" %>
14
13
 
15
14
  <script>
16
15
  $(document).ready(app.admin.<%= module_name_formatted %>.show);
@@ -1,10 +1,11 @@
1
1
  <h1><%= module_name_formatted.pluralize.camelize %></h1>
2
2
 
3
- <table>
3
+ <table class="table">
4
4
  <thead>
5
5
  <tr><%attributes.each do |attribute|%>
6
6
  <%-attribute_args = attribute.split(":")-%>
7
7
  <th><%=attribute_args[0].humanize.titlecase%></th> <%end%>
8
+ <th>&nbsp;</th>
8
9
  </tr>
9
10
  </thead>
10
11
  <tbody>
@@ -1,9 +1,11 @@
1
1
  <h1><%= module_name_formatted.singularize.camelize %></h1>
2
2
 
3
- <%-attributes.each do |attribute|-%>
4
- <%-attribute_args = attribute.split(":")-%>
5
- <p><strong><%=attribute_args[0].humanize.titlecase%></strong> <%%=@<%=module_name_formatted.singularize%>.<%=attribute_args[0]%> %></p>
6
- <%-end-%>
3
+ <dl class="dl-horizontal">
4
+ <%- attribute_names.each do |attribute| -%>
5
+ <dt><%= attribute.humanize.titlecase %>:</dt>
6
+ <dd><%%= @<%= module_name_formatted.singularize %>.<%= attribute %> %></dd>
7
+ <%- end -%>
8
+ </dl>
7
9
 
8
10
  <p><%%= link_to 'Back', <%=module_name_formatted.pluralize%>_path %></p>
9
11
 
@@ -3,6 +3,8 @@
3
3
  <head>
4
4
  <meta charset="utf-8">
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="viewport" content="width=device-width"/>
6
8
  <%%= tb_page_title() %>
7
9
  <%%= stylesheet_link_tag "application", :media => "all" %>
8
10
  <%%= javascript_include_tag "application" %>
@@ -10,14 +12,22 @@
10
12
  <%%= yield :head %>
11
13
  </head>
12
14
  <body>
15
+ <div class="container">
13
16
 
14
- <%% if flash[:notice] %>
15
- <p class="flash flash-notice"><%%= flash[:notice] %> <a href="#" class="flash-remove">X</a></p>
16
- <%% elsif flash[:error] %>
17
- <p class="flash flash-error"><%%= flash[:error] %> <a href="#" class="flash-remove">X</a></p>
18
- <%% end %>
17
+ <%% if flash[:notice] %>
18
+ <div class="alert alert-info alert-dismissible">
19
+ <%%= flash[:notice] %> <a href="#" class="flash-remove">X</a>
20
+ <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
21
+ </div>
22
+ <%% elsif flash[:error] %>
23
+ <div class="alert alert-danger alert-dismissible">
24
+ <%%= flash[:error] %> <a href="#" class="flash-remove">X</a>
25
+ <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
26
+ </div>
27
+ <%% end %>
19
28
 
20
- <%%= content_for?(:body) ? yield(:body) : yield %>
29
+ <%%= content_for?(:body) ? yield(:body) : yield %>
21
30
 
31
+ </div>
22
32
  </body>
23
33
  </html>
@@ -13,7 +13,7 @@ module Spud
13
13
  self.stylesheets = []
14
14
  self.multisite_mode_enabled = false
15
15
  self.multisite_config = []
16
- self.from_address = "no-reply@spudengine.com"
16
+ self.from_address = "no-reply@companyname.com"
17
17
  self.permissions = []
18
18
  self.admin_javascripts = ['admin/core/application', 'admin/application']
19
19
  self.admin_stylesheets = ['admin/core/application', 'admin/application']
@@ -1,9 +1,16 @@
1
1
  require 'jquery-rails'
2
2
  require 'authlogic'
3
- require 'breadcrumbs_on_rails'
3
+ require 'bootstrap-sass'
4
+ require 'autoprefixer-rails'
4
5
  require 'will_paginate'
6
+ require 'will_paginate-bootstrap'
7
+ require 'breadcrumbs_on_rails'
5
8
  require 'tinymce-rails'
6
9
 
10
+ # this should eventually replace the Spud::Core namespace
11
+ module TbCore
12
+ end
13
+
7
14
  module Spud
8
15
  module Core
9
16
  class Engine < ::Rails::Engine
@@ -14,6 +21,7 @@ module Spud
14
21
 
15
22
  engine_name :tb_core
16
23
  config.autoload_paths << "#{root}/lib"
24
+ #config.autoload_paths << File.expand_path("../lib", __FILE__)
17
25
 
18
26
  initializer 'tb_core.controller_overrides' do |config|
19
27
  ActionController::Base.class_eval do
@@ -1,5 +1,5 @@
1
1
  module Spud
2
2
  module Core
3
- VERSION = "1.2.8"
3
+ VERSION = "1.3.0.beta1"
4
4
  end
5
5
  end
@@ -0,0 +1,254 @@
1
+ class TbCore::FormBuilder < ActionView::Helpers::FormBuilder
2
+
3
+ ###############
4
+ # Basic Helpers
5
+ #
6
+ # Use the following methods as the basic building blocks for your forms
7
+ #
8
+
9
+ # Build a form group
10
+ #
11
+ def tb_form_group(content=nil, options={})
12
+ content_tag :div, options.merge(:class => 'form-group') do
13
+ if block_given?
14
+ yield
15
+ else
16
+ content
17
+ end
18
+ end
19
+ end
20
+
21
+ # Build a label
22
+ #
23
+ def tb_label(attribute)
24
+ label(attribute, @object.class.human_attribute_name(attribute), :class => 'col-sm-2 control-label')
25
+ end
26
+
27
+ # Builds an input field with error message
28
+ #
29
+ def tb_input_field_tag(attribute, input_type=nil, options={})
30
+ content_tag(:div, :class => 'col-sm-10') do
31
+ if block_given?
32
+ concat(yield(attribute))
33
+ else
34
+ concat send(input_type, attribute, objectify_options(
35
+ :placeholder => @object.class.human_attribute_name(attribute),
36
+ :class => 'form-control'
37
+ ))
38
+ end
39
+ error_message = @object.errors[attribute].first
40
+ if error_message
41
+ concat content_tag(:p, error_message, :class => 'help-block form-field-error')
42
+ end
43
+ end
44
+ end
45
+
46
+ # Builds a text field
47
+ #
48
+ def tb_text_field_tag(attribute, options={})
49
+ tb_input_field_tag(attribute, :text_field, options)
50
+ end
51
+
52
+ # Builds a text area
53
+ #
54
+ def tb_text_area_tag(attribute, options={})
55
+ tb_input_field_tag(attribute, :text_area, options)
56
+ end
57
+
58
+ # Builds a password field
59
+ #
60
+ def tb_password_field_tag(attribute, options={})
61
+ tb_input_field_tag(attribute, :password_field, options)
62
+ end
63
+
64
+ # Builds a number field
65
+ #
66
+ def tb_number_field_tag(attribute, options={})
67
+ tb_input_field_tag(attribute, :number_field, options)
68
+ end
69
+
70
+ # Builds a check box
71
+ #
72
+ def tb_check_box_tag(attribute, options={})
73
+ tb_input_field_tag(attribute, :check_box, options)
74
+ end
75
+
76
+ # Builds a select tag
77
+ #
78
+ def tb_select_tag(attribute, option_tags, options={}, html_options={})
79
+ tb_input_field_tag(attribute) do
80
+ select(attribute, option_tags, objectify_options(options), html_options.merge(:class => 'form-control'))
81
+ end
82
+ end
83
+
84
+ # Builds a date select tag
85
+ #
86
+ def tb_date_select_tag(attribute, options={}, html_options={})
87
+ options[:with_css_classes] = true
88
+ tb_input_field_tag(attribute) do
89
+ date_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control date-select'))
90
+ end
91
+ end
92
+
93
+ # Builds a date select tag
94
+ #
95
+ def tb_datetime_select_tag(attribute, options={}, html_options={})
96
+ options[:with_css_classes] = true
97
+ tb_input_field_tag(attribute) do
98
+ datetime_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control datetime-select'))
99
+ end
100
+ end
101
+
102
+ # Builds a time select tag
103
+ #
104
+ def tb_time_select_tag(attribute, options={}, html_options={})
105
+ options[:with_css_classes] = true
106
+ tb_input_field_tag(attribute) do
107
+ time_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control datetime-select'))
108
+ end
109
+ end
110
+
111
+ # Builds a row of save/cancel buttons
112
+ #
113
+ def tb_save_buttons(model_name, cancel_path)
114
+ content_tag :div, :class => 'form-group' do
115
+ content_tag :div, :class => 'col-sm-offset-2 col-sm-10' do
116
+ concat submit "Save #{model_name}", :class => 'btn btn-primary'
117
+ concat ' '
118
+ concat @template.link_to 'Cancel', cancel_path, :class => 'btn btn-default'
119
+ end
120
+ end
121
+ end
122
+
123
+ ##################
124
+ # Advanced Helpers
125
+ #
126
+ # These helpers are designed to output an entire form group with child elements
127
+ # ie, container div + label + input + error message
128
+ #
129
+
130
+ # Builds a form group, label, and input tag all in one
131
+ #
132
+ def tb_input_field(attribute, input_type=nil, options={})
133
+ tb_form_group() do
134
+ concat tb_label(attribute)
135
+ if block_given?
136
+ concat(
137
+ tb_input_field_tag(attribute) do
138
+ yield
139
+ end
140
+ )
141
+ else
142
+ if input_type.nil?
143
+ input_type = determine_input_type_from_attribute(attribute)
144
+ end
145
+ concat tb_input_field_tag(attribute, input_type, options)
146
+ end
147
+ end
148
+ end
149
+
150
+ # Builds a text field group
151
+ #
152
+ def tb_text_field(attribute, options={})
153
+ tb_input_field(attribute, :text_field, options)
154
+ end
155
+
156
+ # Builds a text area group
157
+ #
158
+ def tb_text_area(attribute, options={})
159
+ tb_input_field(attribute, :text_area, options)
160
+ end
161
+
162
+ # Builds a password field group
163
+ #
164
+ def tb_password_field(attribute, options={})
165
+ tb_input_field(attribute, :password_field, options)
166
+ end
167
+
168
+ # Builds a number field group
169
+ #
170
+ def tb_number_field(attribute, options={})
171
+ tb_input_field(attribute, :number_field, options)
172
+ end
173
+
174
+ # Builds a check box
175
+ #
176
+ def tb_check_box(attribute, options={})
177
+ tb_input_field(attribute) do
178
+ check_box(attribute, options)
179
+ end
180
+ end
181
+
182
+ # Builds a file field group
183
+ #
184
+ def tb_file_field(attribute, options={})
185
+ tb_input_field(attribute) do
186
+ file_field(attribute)
187
+ end
188
+ end
189
+
190
+ # Builds a select group
191
+ #
192
+ def tb_select(attribute, option_tags, options={}, html_options={})
193
+ tb_input_field(attribute) do
194
+ select(attribute, option_tags, objectify_options(options), html_options.merge(:class => 'form-control'))
195
+ end
196
+ end
197
+
198
+ # Builds a date select tag
199
+ #
200
+ def tb_date_select(attribute, options={}, html_options={})
201
+ options[:with_css_classes] = true
202
+ tb_input_field(attribute) do
203
+ date_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control date-select'))
204
+ end
205
+ end
206
+
207
+ # Builds a date select tag
208
+ #
209
+ def tb_datetime_select(attribute, options={}, html_options={})
210
+ options[:with_css_classes] = true
211
+ tb_input_field(attribute) do
212
+ datetime_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control datetime-select'))
213
+ end
214
+ end
215
+
216
+ # Builds a time select tag
217
+ #
218
+ def tb_time_select(attribute, options={}, html_options={})
219
+ options[:with_css_classes] = true
220
+ tb_input_field(attribute) do
221
+ time_select(attribute, objectify_options(options), html_options.merge(:class => 'form-control datetime-select'))
222
+ end
223
+ end
224
+
225
+ # Builds a time zone select group
226
+ #
227
+ def tb_time_zone_select(attribute, priority_zones, options={}, html_options={})
228
+ tb_input_field(attribute) do
229
+ time_zone_select(attribute, priority_zones, objectify_options(options), html_options.merge(:class => 'form-control'))
230
+ end
231
+ end
232
+
233
+ private
234
+
235
+ def concat(*args)
236
+ @template.concat(*args)
237
+ end
238
+
239
+ def content_tag(*args)
240
+ if block_given?
241
+ @template.content_tag(*args) do
242
+ yield
243
+ end
244
+ else
245
+ @template.content_tag(*args)
246
+ end
247
+ end
248
+
249
+ def determine_input_type_from_attribute(attribute)
250
+ # TODO: Intelligently return the correct input for the given attribute
251
+ return :text_field
252
+ end
253
+
254
+ end
@@ -120,31 +120,31 @@ describe Admin::ApplicationHelper do
120
120
  end
121
121
  end
122
122
 
123
- describe :error_messages_for do
123
+ describe :tb_form_errors do
124
124
  before(:each) do
125
125
  @user = FactoryGirl.create(:spud_user)
126
126
  end
127
127
 
128
128
  it "should return blank when no errors exist" do
129
- helper.error_messages_for(@user).should == ''
129
+ helper.tb_form_errors(@user).should == ''
130
130
  end
131
131
 
132
132
  it "should display 1 error when the subject has 2 errors" do
133
133
  @user.errors[:base] << "error 1"
134
- helper.error_messages_for(@user).should include("1 error")
134
+ helper.tb_form_errors(@user).should include("1 error")
135
135
  end
136
136
 
137
137
  (1..3).each do |error_count|
138
138
  it "should display #{error_count} errors when the subject has #{error_count} errors" do
139
139
  error_count.times {|x| @user.errors[:base] << "error #{x}" }
140
- helper.error_messages_for(@user).should include("#{@user.errors[:base].size} error")
140
+ helper.tb_form_errors(@user).should include("#{@user.errors[:base].size} error")
141
141
  end
142
142
  end
143
143
 
144
144
  it "should display the error" do
145
145
  error = "You're invalid"
146
146
  @user.errors[:base] << error
147
- helper.error_messages_for(@user).should include(error)
147
+ helper.tb_form_errors(@user).should include(error)
148
148
  end
149
149
  end
150
150
  end