dry_crud 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +8 -8
  2. data/README.rdoc +67 -33
  3. data/VERSION +1 -1
  4. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/add.png +0 -0
  5. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/delete.png +0 -0
  6. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/edit.png +0 -0
  7. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/list.png +0 -0
  8. data/{lib/generators/dry_crud/templates/app → app}/assets/images/actions/show.png +0 -0
  9. data/{lib/generators/dry_crud/templates/app → app}/assets/stylesheets/crud.scss +12 -22
  10. data/{lib/generators/dry_crud/templates/app → app}/assets/stylesheets/sample.scss +157 -106
  11. data/{lib/generators/dry_crud/templates/app → app}/controllers/crud_controller.rb +15 -16
  12. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/generic_model.rb +7 -7
  13. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/nestable.rb +2 -2
  14. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/rememberable.rb +3 -3
  15. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/render_callbacks.rb +2 -2
  16. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/responder.rb +2 -2
  17. data/app/controllers/dry_crud/searchable.rb +77 -0
  18. data/{lib/generators/dry_crud/templates/app/controllers/crud → app/controllers/dry_crud}/sortable.rb +9 -7
  19. data/{lib/generators/dry_crud/templates/app → app}/controllers/list_controller.rb +11 -9
  20. data/{lib/generators/dry_crud/templates/app → app}/helpers/actions_helper.rb +2 -2
  21. data/{lib/generators/dry_crud/templates/app/helpers/crud/form_builder.rb → app/helpers/dry_crud/form/builder.rb} +147 -164
  22. data/app/helpers/dry_crud/form/control.rb +180 -0
  23. data/app/helpers/dry_crud/table/actions.rb +88 -0
  24. data/app/helpers/dry_crud/table/builder.rb +115 -0
  25. data/app/helpers/dry_crud/table/col.rb +25 -0
  26. data/app/helpers/dry_crud/table/sorting.rb +61 -0
  27. data/{lib/generators/dry_crud/templates/app → app}/helpers/form_helper.rb +3 -2
  28. data/{lib/generators/dry_crud/templates/app → app}/helpers/format_helper.rb +5 -5
  29. data/{lib/generators/dry_crud/templates/app → app}/helpers/i18n_helper.rb +2 -2
  30. data/{lib/generators/dry_crud/templates/app → app}/helpers/table_helper.rb +8 -7
  31. data/{lib/generators/dry_crud/templates/app → app}/helpers/utility_helper.rb +1 -1
  32. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_edit.html.erb +0 -0
  33. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_edit.html.haml +0 -0
  34. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_index.html.erb +0 -0
  35. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_index.html.haml +0 -0
  36. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_show.html.erb +0 -0
  37. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_actions_show.html.haml +0 -0
  38. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_attrs.html.erb +0 -0
  39. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_attrs.html.haml +0 -0
  40. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_form.html.erb +0 -0
  41. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_form.html.haml +0 -0
  42. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_list.html.erb +0 -0
  43. data/{lib/generators/dry_crud/templates/app → app}/views/crud/_list.html.haml +0 -0
  44. data/{lib/generators/dry_crud/templates/app → app}/views/crud/edit.html.erb +0 -0
  45. data/{lib/generators/dry_crud/templates/app → app}/views/crud/edit.html.haml +0 -0
  46. data/{lib/generators/dry_crud/templates/app → app}/views/crud/new.html.erb +0 -0
  47. data/{lib/generators/dry_crud/templates/app → app}/views/crud/new.html.haml +0 -0
  48. data/{lib/generators/dry_crud/templates/app → app}/views/crud/show.html.erb +0 -0
  49. data/{lib/generators/dry_crud/templates/app → app}/views/crud/show.html.haml +0 -0
  50. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_flash.html.erb +0 -0
  51. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_flash.html.haml +0 -0
  52. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_nav.html.erb +2 -2
  53. data/{lib/generators/dry_crud/templates/app → app}/views/layouts/_nav.html.haml +2 -2
  54. data/{lib/generators/dry_crud/templates/app/views/layouts/crud.html.erb → app/views/layouts/application.html.erb} +22 -16
  55. data/{lib/generators/dry_crud/templates/app/views/layouts/crud.html.haml → app/views/layouts/application.html.haml} +17 -11
  56. data/{lib/generators/dry_crud/templates/app → app}/views/list/_actions_index.html.erb +0 -0
  57. data/{lib/generators/dry_crud/templates/app → app}/views/list/_actions_index.html.haml +0 -0
  58. data/{lib/generators/dry_crud/templates/app → app}/views/list/_list.html.erb +0 -0
  59. data/{lib/generators/dry_crud/templates/app → app}/views/list/_list.html.haml +0 -0
  60. data/app/views/list/_search.html.erb +10 -0
  61. data/app/views/list/_search.html.haml +7 -0
  62. data/{lib/generators/dry_crud/templates/app → app}/views/list/index.html.erb +0 -0
  63. data/{lib/generators/dry_crud/templates/app → app}/views/list/index.html.haml +0 -0
  64. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_error_messages.html.erb +1 -1
  65. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_error_messages.html.haml +1 -1
  66. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_labeled.html.erb +0 -0
  67. data/{lib/generators/dry_crud/templates/app → app}/views/shared/_labeled.html.haml +0 -0
  68. data/{lib/generators/dry_crud/templates/config → config}/locales/crud.de.yml +0 -0
  69. data/{lib/generators/dry_crud/templates/config → config}/locales/crud.en.yml +0 -0
  70. data/lib/dry_crud/engine.rb +18 -0
  71. data/lib/dry_crud.rb +5 -0
  72. data/lib/generators/dry_crud/dry_crud_generator.rb +12 -20
  73. data/lib/generators/dry_crud/dry_crud_generator_base.rb +57 -0
  74. data/lib/generators/dry_crud/file_generator.rb +41 -0
  75. data/lib/generators/dry_crud/templates/INSTALL +1 -1
  76. data/lib/generators/dry_crud/templates/spec/controllers/crud_test_models_controller_spec.rb +1 -1
  77. data/lib/generators/dry_crud/templates/spec/helpers/{crud/form_builder_spec.rb → dry_crud/form/builder_spec.rb} +28 -19
  78. data/lib/generators/dry_crud/templates/spec/helpers/{crud/table_builder_spec.rb → dry_crud/table/builder_spec.rb} +3 -3
  79. data/lib/generators/dry_crud/templates/spec/helpers/form_helper_spec.rb +21 -40
  80. data/lib/generators/dry_crud/templates/spec/helpers/format_helper_spec.rb +36 -26
  81. data/lib/generators/dry_crud/templates/spec/helpers/table_helper_spec.rb +4 -4
  82. data/lib/generators/dry_crud/templates/spec/helpers/utility_helper_spec.rb +6 -6
  83. data/lib/generators/dry_crud/templates/spec/support/crud_controller_examples.rb +1 -1
  84. data/lib/generators/dry_crud/templates/spec/support/crud_controller_test_helper.rb +0 -1
  85. data/lib/generators/dry_crud/templates/test/helpers/{crud/form_builder_test.rb → dry_crud/form/builder_test.rb} +38 -25
  86. data/lib/generators/dry_crud/templates/test/helpers/{crud/table_builder_test.rb → dry_crud/table/builder_test.rb} +4 -4
  87. data/lib/generators/dry_crud/templates/test/helpers/form_helper_test.rb +12 -9
  88. data/lib/generators/dry_crud/templates/test/helpers/format_helper_test.rb +13 -1
  89. data/lib/generators/dry_crud/templates/test/helpers/table_helper_test.rb +4 -4
  90. data/lib/generators/dry_crud/templates/test/support/crud_controller_test_helper.rb +3 -3
  91. data/lib/generators/dry_crud/templates/test/support/crud_test_model.rb +2 -2
  92. metadata +76 -68
  93. data/lib/generators/dry_crud/templates/app/controllers/crud/searchable.rb +0 -55
  94. data/lib/generators/dry_crud/templates/app/helpers/crud/table_builder.rb +0 -280
  95. data/lib/generators/dry_crud/templates/app/views/list/_search.html.erb +0 -6
  96. data/lib/generators/dry_crud/templates/app/views/list/_search.html.haml +0 -5
@@ -0,0 +1,115 @@
1
+ # encoding: UTF-8
2
+
3
+ module DryCrud::Table
4
+ # A simple helper to easily define tables listing several rows of the same
5
+ # data type.
6
+ #
7
+ # Example Usage:
8
+ # DryCrud::Table::Builder.table(entries, template) do |t|
9
+ # t.col('My Header', class: 'css') {|e| link_to 'Show', e }
10
+ # t.attrs :name, :city
11
+ # end
12
+ class Builder
13
+
14
+ include Sorting
15
+ include Actions
16
+
17
+ attr_reader :entries, :cols, :options, :template
18
+
19
+ delegate :content_tag, :format_attr, :column_type, :association, :dom_id,
20
+ :captionize, :add_css_class, :content_tag_nested,
21
+ to: :template
22
+
23
+ def initialize(entries, template, options = {})
24
+ @entries = entries
25
+ @template = template
26
+ @options = options
27
+ @cols = []
28
+ end
29
+
30
+ # Convenience method to directly generate a table. Renders a row for each
31
+ # entry in entries. Takes a block that gets the table object as parameter
32
+ # for configuration. Returns the generated html for the table.
33
+ def self.table(entries, template, options = {})
34
+ t = new(entries, template, options)
35
+ yield t
36
+ t.to_html
37
+ end
38
+
39
+ # Define a column for the table with the given header, the html_options
40
+ # used for each td and a block rendering the contents of a cell for the
41
+ # current entry. The columns appear in the order they are defined.
42
+ def col(header = '', html_options = {}, &block)
43
+ @cols << Col.new(header, html_options, @template, block)
44
+ end
45
+
46
+ # Convenience method to add one or more attribute columns.
47
+ # The attribute name will become the header, the cells will contain
48
+ # the formatted attribute value for the current entry.
49
+ def attrs(*attrs)
50
+ attrs.each do |a|
51
+ attr(a)
52
+ end
53
+ end
54
+
55
+ # Define a column for the given attribute and an optional header.
56
+ # If no header is given, the attribute name is used. The cell will
57
+ # contain the formatted attribute value for the current entry.
58
+ def attr(a, header = nil, html_options = {}, &block)
59
+ header ||= attr_header(a)
60
+ block ||= ->(e) { format_attr(e, a) }
61
+ add_css_class(html_options, align_class(a))
62
+ col(header, html_options, &block)
63
+ end
64
+
65
+ # Renders the table as HTML.
66
+ def to_html
67
+ content_tag :table, options do
68
+ content_tag(:thead, html_header) +
69
+ content_tag_nested(:tbody, entries) { |e| html_row(e) }
70
+ end
71
+ end
72
+
73
+ # Returns css classes used for alignment of the cell data.
74
+ # Based on the column type of the attribute.
75
+ def align_class(attr)
76
+ entry = entries.present? ? entry_class.new : nil
77
+ case column_type(entry, attr)
78
+ when :integer, :float, :decimal
79
+ 'right' unless association(entry, attr, :belongs_to)
80
+ when :boolean
81
+ 'center'
82
+ end
83
+ end
84
+
85
+ # Creates a header string for the given attr.
86
+ def attr_header(attr)
87
+ captionize(attr, entry_class)
88
+ end
89
+
90
+ private
91
+
92
+ # Renders the header row of the table.
93
+ def html_header
94
+ content_tag_nested(:tr, cols) { |c| c.html_header }
95
+ end
96
+
97
+ # Renders a table row for the given entry.
98
+ def html_row(entry)
99
+ attrs = {}
100
+ attrs[:id] = dom_id(entry) if entry.respond_to?(:to_key)
101
+ content_tag_nested(:tr, cols, attrs) { |c| c.html_cell(entry) }
102
+ end
103
+
104
+ # Determines the class of the table entries.
105
+ # All entries should be of the same type.
106
+ def entry_class
107
+ if entries.respond_to?(:klass)
108
+ entries.klass
109
+ else
110
+ entries.first.class
111
+ end
112
+ end
113
+
114
+ end
115
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+
3
+ module DryCrud::Table
4
+ # Helper class to store column information.
5
+ class Col < Struct.new(:header, :html_options, :template, :block) #:nodoc:
6
+
7
+ delegate :content_tag, :capture, to: :template
8
+
9
+ # Runs the Col block for the given entry.
10
+ def content(entry)
11
+ entry.nil? ? '' : capture(entry, &block)
12
+ end
13
+
14
+ # Renders the header cell of the Col.
15
+ def html_header
16
+ content_tag(:th, header, html_options)
17
+ end
18
+
19
+ # Renders a table cell for the given entry.
20
+ def html_cell(entry)
21
+ content_tag(:td, content(entry), html_options)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: UTF-8
2
+
3
+ module DryCrud::Table
4
+ # Provides headers with sort links. Expects a method :sortable?(attr)
5
+ # in the template/controller to tell if an attribute is sortable or not.
6
+ # Extracted into an own module for convenience.
7
+ module Sorting
8
+ # Create a header with sort links and a mark for the current sort
9
+ # direction.
10
+ def sort_header(attr, label = nil)
11
+ label ||= attr_header(attr)
12
+ template.link_to(label, sort_params(attr)) + current_mark(attr)
13
+ end
14
+
15
+ # Same as :attrs, except that it renders a sort link in the header
16
+ # if an attr is sortable.
17
+ def sortable_attrs(*attrs)
18
+ attrs.each { |a| sortable_attr(a) }
19
+ end
20
+
21
+ # Renders a sort link header, otherwise similar to :attr.
22
+ def sortable_attr(a, header = nil, &block)
23
+ if template.sortable?(a)
24
+ attr(a, sort_header(a, header), &block)
25
+ else
26
+ attr(a, header, &block)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ # Request params for the sort link.
33
+ def sort_params(attr)
34
+ params.merge(sort: attr, sort_dir: sort_dir(attr))
35
+ end
36
+
37
+ # The sort mark, if any, for the given attribute.
38
+ def current_mark(attr)
39
+ if current_sort?(attr)
40
+ (sort_dir(attr) == 'asc' ? ' &uarr;' : ' &darr;').html_safe
41
+ else
42
+ ''
43
+ end
44
+ end
45
+
46
+ # Returns true if the given attribute is the current sort column.
47
+ def current_sort?(attr)
48
+ params[:sort] == attr.to_s
49
+ end
50
+
51
+ # The sort direction to use in the sort link for the given attribute.
52
+ def sort_dir(attr)
53
+ current_sort?(attr) && params[:sort_dir] == 'asc' ? 'desc' : 'asc'
54
+ end
55
+
56
+ # Delegate to template.
57
+ def params
58
+ template.params
59
+ end
60
+ end
61
+ end
@@ -13,7 +13,8 @@ module FormHelper
13
13
  def plain_form(object, options = {}, &block)
14
14
  options[:html] ||= {}
15
15
  add_css_class(options[:html], 'form-horizontal')
16
- options[:builder] ||= Crud::FormBuilder
16
+ options[:html][:role] ||= 'form'
17
+ options[:builder] ||= DryCrud::Form::Builder
17
18
  options[:cancel_url] ||= polymorphic_path(object, returning: true)
18
19
 
19
20
  form_for(object, options, &block)
@@ -49,4 +50,4 @@ module FormHelper
49
50
  standard_form(path_args(entry), *attrs, &block)
50
51
  end
51
52
 
52
- end
53
+ end
@@ -112,7 +112,7 @@ module FormatHelper
112
112
  # special types that have no own object class.
113
113
  def format_type(obj, attr)
114
114
  val = obj.send(attr)
115
- return UtilityHelper::EMPTY_STRING if val.blank?
115
+ return UtilityHelper::EMPTY_STRING if val.blank? && val != false
116
116
 
117
117
  case column_type(obj, attr)
118
118
  when :time then l(val, format: :time)
@@ -152,13 +152,13 @@ module FormatHelper
152
152
 
153
153
  # Renders a link to the given association entry.
154
154
  def assoc_link(assoc, val)
155
- link_to_unless(no_assoc_link?(assoc, val), val.to_s, val)
155
+ link_to_if(assoc_link?(assoc, val), val.to_s, val)
156
156
  end
157
157
 
158
158
  # Returns true if no link should be created when formatting the given
159
159
  # association.
160
- def no_assoc_link?(assoc, val)
161
- !respond_to?("#{val.class.model_name.singular_route_key}_path".to_sym)
160
+ def assoc_link?(assoc, val)
161
+ respond_to?("#{val.class.model_name.singular_route_key}_path".to_sym)
162
162
  end
163
163
 
164
- end
164
+ end
@@ -31,7 +31,7 @@ module I18nHelper
31
31
  # - activerecord.associations.{association_model_name}.{key}
32
32
  # - global.associations.{key}
33
33
  def translate_association(key, assoc = nil, variables = {})
34
- if assoc
34
+ if assoc && assoc.options[:polymorphic].nil?
35
35
  variables[:default] ||= [association_klass_key(assoc, key).to_sym,
36
36
  :"global.associations.#{key}"]
37
37
  t(association_owner_key(assoc, key), variables)
@@ -82,4 +82,4 @@ module I18nHelper
82
82
  defaults << :"#{folder}.global.#{key}"
83
83
  end
84
84
 
85
- end
85
+ end
@@ -17,8 +17,9 @@ module TableHelper
17
17
  # An options hash may be given as the last argument.
18
18
  def plain_table(entries, *attrs, &block)
19
19
  options = attrs.extract_options!
20
- add_css_class(options, 'table')
21
- Crud::TableBuilder.table(entries, self, options) do |t|
20
+ add_css_class(options, 'table table-striped table-hover')
21
+ builder = options.delete(:builder) || DryCrud::Table::Builder
22
+ builder.table(entries, self, options) do |t|
22
23
  t.attrs(*attrs)
23
24
  yield t if block_given?
24
25
  end
@@ -57,10 +58,10 @@ module TableHelper
57
58
  attrs, options = explode_attrs_with_options(attrs, &block)
58
59
  first = attrs.shift
59
60
  plain_table_or_message(entries, options) do |t|
60
- t.attr_with_show_link(first) if first
61
- t.sortable_attrs(*attrs)
62
- yield t if block_given?
63
- standard_table_actions(t)
61
+ t.attr_with_show_link(first) if first
62
+ t.sortable_attrs(*attrs)
63
+ yield t if block_given?
64
+ standard_table_actions(t)
64
65
  end
65
66
  end
66
67
 
@@ -80,4 +81,4 @@ module TableHelper
80
81
  [attrs, options]
81
82
  end
82
83
 
83
- end
84
+ end
@@ -14,7 +14,7 @@ module UtilityHelper
14
14
  # Overridden method that takes a block that is executed for each item in
15
15
  # array before appending the results.
16
16
  def safe_join(array, sep = $OUTPUT_FIELD_SEPARATOR, &block)
17
- super(block_given? ? array.map(&block) : array, sep)
17
+ super(block_given? ? array.map(&block).compact : array, sep)
18
18
  end
19
19
 
20
20
  # Returns the css class for the given flash level.
@@ -1,5 +1,5 @@
1
- <%= link_to 'MyApp', root_path, class: 'brand' %>
2
- <ul class="nav">
1
+ <%= link_to 'MyApp', root_path, class: 'navbar-brand' %>
2
+ <ul class="nav navbar-nav">
3
3
  <li><%= link_to "Link1", "/path1" %></li>
4
4
  <li><%= link_to "Link2", "/path2" %></li>
5
5
  <li><%= link_to "Link3", "/path3" %></li>
@@ -1,5 +1,5 @@
1
- = link_to 'MyApp', root_path, class: 'brand'
2
- %ul.nav
1
+ = link_to 'MyApp', root_path, class: 'navbar-brand'
2
+ %ul.nav.navbar-nav
3
3
  %li= link_to "Link1", "/path1"
4
4
  %li= link_to "Link2", "/path2"
5
5
  %li= link_to "Link3", "/path3"
@@ -4,17 +4,19 @@
4
4
  <head>
5
5
  <meta charset="utf-8" />
6
6
  <title><%= strip_tags(@title) %> - MyApp</title>
7
- <%= csrf_meta_tag %>
8
7
 
9
- <!-- HTML5 shim, for IE6-8 support of HTML elements -->
10
- <!--[if lt IE 9]>
11
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
12
- <![endif]-->
8
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
9
+ <%= csrf_meta_tag %>
13
10
 
14
11
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
15
12
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
16
13
 
17
- <!-- fav and touch icons -->
14
+ <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
15
+ <!--[if lt IE 9]>
16
+ <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
17
+ <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
18
+ <![endif]-->
19
+
18
20
  <%= favicon_link_tag %>
19
21
  <%= favicon_link_tag '/apple-touch-icon.png',
20
22
  rel: 'apple-touch-icon',
@@ -32,25 +34,29 @@
32
34
  </head>
33
35
  <body>
34
36
 
37
+ <nav class="navbar navbar-default" role="navigation">
38
+ <%= render 'layouts/nav' %>
39
+ </nav>
35
40
 
36
41
  <div class="container">
37
- <div class="navbar">
38
- <%= render 'layouts/nav' %>
39
- </div>
40
42
 
41
43
  <h1><%= @title %></h1>
42
44
 
43
- <%= render partial: 'layouts/flash', collection: [:notice, :alert], as: :level %>
44
-
45
- <div class="actions btn-toolbar">
46
- <div class="pull-right">
47
- <%= yield :actions %>
45
+ <div class="row actions">
46
+ <div class="col-md-5">
47
+ <%= yield :tools %>
48
48
  </div>
49
- <div class="pull-left">
50
- <%= yield :tools %>
49
+ <div class="col-md-7">
50
+ <div class="btn-toolbar pull-right">
51
+ <%= yield :actions %>
52
+ </div>
51
53
  </div>
52
54
  </div>
53
55
 
56
+ <div id="flash">
57
+ <%= render partial: 'layouts/flash', collection: [:notice, :alert], as: :level %>
58
+ </div>
59
+
54
60
  <div id="content">
55
61
  <%= yield %>
56
62
  </div>
@@ -6,16 +6,18 @@
6
6
  %title
7
7
  = strip_tags(@title)
8
8
  \- MyApp
9
- = csrf_meta_tag
10
9
 
11
- <!-- HTML5 shim, for IE6-8 support of HTML elements -->
12
- <!--[if lt IE 9]>
13
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
14
- <![endif]-->
10
+ %meta{name: 'viewport', content: 'width=device-width, initial-scale=1.0'}
11
+ = csrf_meta_tag
15
12
 
16
13
  = stylesheet_link_tag 'application', :media => 'all', 'data-turbolinks-track' => true
17
14
  = javascript_include_tag 'application', 'data-turbolinks-track' => true
18
15
 
16
+ / HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries
17
+ /[if lt IE 9]
18
+ %script{src: 'https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js'}
19
+ %script{src: 'https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js'}
20
+
19
21
  = favicon_link_tag
20
22
  = favicon_link_tag '/apple-touch-icon.png',
21
23
  rel: 'apple-touch-icon',
@@ -32,16 +34,20 @@
32
34
  = yield :head
33
35
 
34
36
  %body
37
+ %nav.navbar.navbar-default{role: 'navigation'}
38
+ = render 'layouts/nav'
39
+
35
40
  .container
36
- .navbar= render 'layouts/nav'
37
-
38
41
  %h1= @title
39
42
 
40
- = render partial: 'layouts/flash', collection: [:notice, :alert], as: :level
43
+ .row.actions
44
+ .col-md-5
45
+ = yield :tools
46
+ .col-md-7
47
+ .btn-toolbar.pull-right
48
+ = yield :actions
41
49
 
42
- .actions.btn-toolbar
43
- .pull-right= yield :actions
44
- .pull-left= yield :tools
50
+ #flash= render partial: 'layouts/flash', collection: [:notice, :alert], as: :level
45
51
 
46
52
  #content= yield
47
53
 
@@ -0,0 +1,10 @@
1
+ <%= form_tag(nil, method: :get, role: 'search', class: 'form-inline') do %>
2
+ <%= hidden_field_tag :returning, true %>
3
+ <%= hidden_field_tag :page, 1 %>
4
+ <div class="input-group">
5
+ <%= search_field_tag :q, params[:q], class: 'form-control' %>
6
+ <span class="input-group-btn">
7
+ <%= submit_tag ti(:"button.search"), class: 'btn btn-default' %>
8
+ </span>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,7 @@
1
+ = form_tag(nil, { method: :get, class: 'form-inline', role: 'search' }) do
2
+ = hidden_field_tag :returning, true
3
+ = hidden_field_tag :page, 1
4
+ .input-group
5
+ = search_field_tag :q, params[:q], class: 'form-control'
6
+ %span.input-group-btn
7
+ = submit_tag ti(:"button.search"), class: 'btn btn-default'
@@ -1,5 +1,5 @@
1
1
  <% if errors.any? %>
2
- <div id='error_explanation' class='alert alert-error'>
2
+ <div id='error_explanation' class='alert alert-danger'>
3
3
  <h2>
4
4
  <%= ti(:"errors.header", count: errors.count, model: object.to_s) %>
5
5
  </h2>
@@ -1,5 +1,5 @@
1
1
  - if errors.any?
2
- #error_explanation.alert.alert-error
2
+ #error_explanation.alert.alert-danger
3
3
  %h2= ti(:"errors.header", count: errors.count, model: object.to_s)
4
4
  %ul
5
5
  - errors.full_messages.each do |msg|
@@ -0,0 +1,18 @@
1
+ module DryCrud
2
+ class Engine < Rails::Engine
3
+
4
+
5
+ initializer "dry_crud.field_error_proc" do |app|
6
+ # Fields with errors are directly styled in DryCrud::FormBuilder.
7
+ # Rails should just output the plain html tag.
8
+ ActionView::Base.field_error_proc = proc { |html_tag, instance| html_tag }
9
+
10
+ # Load dry_crud engine helpers first so that the application may override them.
11
+ paths = ApplicationController.helpers_path
12
+ if dry_crud_helpers = paths.detect {|p| p =~ /dry_crud(-\d+\.\d+\.\d+)?#{File::SEPARATOR}app#{File::SEPARATOR}helpers\z/ }
13
+ paths.delete(dry_crud_helpers)
14
+ paths.prepend(dry_crud_helpers)
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/dry_crud.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'dry_crud/engine'
2
+
3
+ module DryCrud
4
+
5
+ end
@@ -1,23 +1,24 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'rails/generators'
3
+ begin
4
+ require 'generators/dry_crud/dry_crud_generator_base'
5
+ rescue LoadError => e
6
+ # ok, we are in the rake task
7
+ end
4
8
 
5
9
  # Copies all dry_crud files to the rails application.
6
- class DryCrudGenerator < Rails::Generators::Base
10
+ class DryCrudGenerator < DryCrudGeneratorBase
11
+
12
+ desc 'Copy all dry_crud files to the application.'
7
13
 
8
14
  class_options %w(templates -t) => 'erb'
9
15
  class_options %w(tests) => 'testunit'
10
16
 
11
- def self.source_root
12
- File.join(File.dirname(__FILE__), 'templates')
13
- end
14
-
15
- # copy everything in template subfolders
17
+ # copy everything to application
16
18
  def install_dry_crud
17
- Dir.chdir(self.class.source_root) do
18
- Dir.glob(File.join('**', '**')).sort.each do |file_source|
19
- copy_file_source(file_source) if should_copy?(file_source)
20
- end
19
+ copy_files(all_template_files)
20
+
21
+ Dir.chdir(self.class.template_root) do
21
22
  copy_crud_test_model
22
23
  end
23
24
 
@@ -27,20 +28,11 @@ class DryCrudGenerator < Rails::Generators::Base
27
28
  private
28
29
 
29
30
  def should_copy?(file_source)
30
- !File.directory?(file_source) &&
31
31
  !file_source.end_with?(exclude_template) &&
32
32
  !file_source.start_with?(exclude_test_dir) &&
33
33
  file_source != 'INSTALL'
34
34
  end
35
35
 
36
- def copy_file_source(file_source)
37
- if file_source.end_with?('.erb')
38
- copy_file(file_source)
39
- else
40
- template(file_source)
41
- end
42
- end
43
-
44
36
  def copy_crud_test_model
45
37
  unless exclude_test_dir == 'spec'
46
38
  template(File.join('test', 'support', 'crud_test_model.rb'),