trestle 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/app/assets/javascripts/trestle/components/_datepicker.js +18 -3
  4. data/app/assets/javascripts/trestle/components/_dialog.js +5 -1
  5. data/app/assets/javascripts/trestle/components/_form.js +3 -1
  6. data/app/assets/javascripts/trestle/core/_l10n.js +23 -0
  7. data/app/assets/stylesheets/trestle/components/_avatar.scss +23 -0
  8. data/app/assets/stylesheets/trestle/components/_datepicker.scss +28 -0
  9. data/app/assets/stylesheets/trestle/components/_input-group.scss +18 -0
  10. data/app/helpers/trestle/avatar_helper.rb +7 -2
  11. data/app/helpers/trestle/debug_helper.rb +1 -1
  12. data/app/helpers/trestle/form_helper.rb +1 -1
  13. data/app/helpers/trestle/i18n_helper.rb +14 -0
  14. data/app/helpers/trestle/tab_helper.rb +2 -2
  15. data/app/helpers/trestle/url_helper.rb +37 -9
  16. data/app/views/layouts/trestle/admin.html.erb +1 -3
  17. data/app/views/trestle/application/_layout.html.erb +1 -1
  18. data/app/views/trestle/application/_tabs.html.erb +1 -1
  19. data/app/views/trestle/{application → flash}/_alert.html.erb +2 -2
  20. data/app/views/trestle/flash/_debug.html.erb +8 -0
  21. data/app/views/trestle/flash/_flash.html.erb +7 -0
  22. data/app/views/trestle/resource/edit.html.erb +5 -5
  23. data/app/views/trestle/resource/index.html.erb +2 -2
  24. data/app/views/trestle/resource/new.html.erb +4 -4
  25. data/app/views/trestle/resource/show.html.erb +5 -5
  26. data/app/views/trestle/shared/_sidebar.html.erb +2 -2
  27. data/config/locales/cs.rb +18 -0
  28. data/config/locales/cs.yml +95 -0
  29. data/config/locales/en.yml +43 -22
  30. data/config/locales/fr.yml +37 -22
  31. data/config/locales/nl.yml +37 -22
  32. data/config/locales/pl.yml +37 -22
  33. data/config/locales/pt-BR.yml +37 -22
  34. data/config/locales/zh-CN.rb +18 -0
  35. data/config/locales/zh-CN.yml +94 -0
  36. data/gemfiles/rails-5.2.gemfile +14 -0
  37. data/lib/trestle/adapters/adapter.rb +3 -3
  38. data/lib/trestle/admin.rb +30 -2
  39. data/lib/trestle/admin/builder.rb +17 -7
  40. data/lib/trestle/breadcrumb.rb +3 -1
  41. data/lib/trestle/configurable.rb +6 -0
  42. data/lib/trestle/configuration.rb +7 -1
  43. data/lib/trestle/engine.rb +5 -1
  44. data/lib/trestle/form/fields/date_picker.rb +2 -2
  45. data/lib/trestle/form/fields/form_group.rb +1 -1
  46. data/lib/trestle/resource.rb +38 -3
  47. data/lib/trestle/resource/builder.rb +10 -0
  48. data/lib/trestle/resource/controller.rb +36 -22
  49. data/lib/trestle/tab.rb +4 -0
  50. data/lib/trestle/table/column.rb +4 -4
  51. data/lib/trestle/table/row.rb +1 -1
  52. data/lib/trestle/version.rb +1 -1
  53. data/vendor/assets/javascripts/trestle/flatpickr.js.erb +2 -0
  54. metadata +12 -4
  55. data/app/views/trestle/application/_flash.html.erb +0 -25
@@ -4,19 +4,6 @@ pl:
4
4
  footer: "Powered by Trestle"
5
5
  version: "Wersja"
6
6
 
7
- flash:
8
- success:
9
- title: "Sukces!"
10
- create: "%{lowercase_model_name} został pomyślnie utworzony."
11
- update: "%{lowercase_model_name} został pomyślnie zaktualizowany."
12
- destroy: "%{lowercase_model_name} został pomyślnie usunięty."
13
-
14
- failure:
15
- title: "Uwaga!"
16
- create: "Popraw poniższe błędy."
17
- update: "Popraw poniższe błędy."
18
- destroy: "Nie można usunąć %{lowercase_model_name}."
19
-
20
7
  helpers:
21
8
  page_entries_info:
22
9
  one_page:
@@ -35,6 +22,15 @@ pl:
35
22
  no_template: "Aby dostosować ten szablon, utwórz <code>%{path}</code>."
36
23
  no_form: "Proszę zdefiniować blok formularza lub utworzyć podszablon <code>_form.html</code>."
37
24
 
25
+ ui:
26
+ toggle_navigation: "Przełącz nawigację"
27
+ toggle_sidebar: "Przełącz pasek boczny"
28
+
29
+ confirmation:
30
+ title: "Jesteś pewny?"
31
+ delete: "Usuń"
32
+ cancel: "Anuluj"
33
+
38
34
  admin:
39
35
  titles:
40
36
  index: "Lista %{pluralized_model_name}"
@@ -49,6 +45,34 @@ pl:
49
45
  breadcrumbs:
50
46
  home: "Start"
51
47
 
48
+ flash:
49
+ create:
50
+ success:
51
+ title: "Sukces!"
52
+ message: "%{lowercase_model_name} został pomyślnie utworzony."
53
+
54
+ failure:
55
+ title: "Uwaga!"
56
+ message: "Popraw poniższe błędy."
57
+
58
+ update:
59
+ success:
60
+ title: "Sukces!"
61
+ message: "%{lowercase_model_name} został pomyślnie zaktualizowany."
62
+
63
+ failure:
64
+ title: "Uwaga!"
65
+ message: "Popraw poniższe błędy."
66
+
67
+ destroy:
68
+ success:
69
+ title: "Sukces!"
70
+ message: "%{lowercase_model_name} został pomyślnie usunięty."
71
+
72
+ failure:
73
+ title: "Uwaga!"
74
+ message: "Nie można usunąć %{lowercase_model_name}."
75
+
52
76
  table:
53
77
  headers:
54
78
  id: "ID"
@@ -57,14 +81,5 @@ pl:
57
81
  select:
58
82
  prompt: "- Wybierz %{attribute_name} -"
59
83
 
60
- confirmation:
61
- title: "Jesteś pewny?"
62
- delete: "Usuń"
63
- cancel: "Anuluj"
64
-
65
- ui:
66
- toggle_navigation: "Przełącz nawigację"
67
- toggle_sidebar: "Przełącz pasek boczny"
68
-
69
84
  format:
70
85
  blank: "Żaden"
@@ -4,19 +4,6 @@ pt-BR:
4
4
  footer: "Powered by Trestle"
5
5
  version: "Versão"
6
6
 
7
- flash:
8
- success:
9
- title: "Sucesso!"
10
- create: "O %{model_name} foi criado com sucesso."
11
- update: "O %{model_name} foi atualizado com sucesso."
12
- destroy: "O %{model_name} foi deletado com sucesso."
13
-
14
- failure:
15
- title: "Atenção!"
16
- create: "Por favor corrija os erros abaixo."
17
- update: "Por favor corrija os erros abaixo."
18
- destroy: "Falha ao excluir %{model_name}."
19
-
20
7
  helpers:
21
8
  page_entries_info:
22
9
  one_page:
@@ -34,6 +21,15 @@ pt-BR:
34
21
  no_template: "Para personalizar este template, crie <code>%{path}</code>."
35
22
  no_form: "Defina um bloco de formulário ou crie um <code>_form.html</code> parcial."
36
23
 
24
+ ui:
25
+ toggle_navigation: "Alternar naveção"
26
+ toggle_sidebar: "Alternar barra lateral"
27
+
28
+ confirmation:
29
+ title: "Você tem certeza?"
30
+ delete: "Excluir"
31
+ cancel: "Cancelar"
32
+
37
33
  admin:
38
34
  titles:
39
35
  index: "Listando %{pluralized_model_name}"
@@ -48,6 +44,34 @@ pt-BR:
48
44
  breadcrumbs:
49
45
  home: "Home"
50
46
 
47
+ flash:
48
+ create:
49
+ success:
50
+ title: "Sucesso!"
51
+ message: "O %{model_name} foi criado com sucesso."
52
+
53
+ failure:
54
+ title: "Atenção!"
55
+ message: "Por favor corrija os erros abaixo."
56
+
57
+ update:
58
+ success:
59
+ title: "Sucesso!"
60
+ message: "O %{model_name} foi atualizado com sucesso."
61
+
62
+ failure:
63
+ title: "Atenção!"
64
+ message: "Por favor corrija os erros abaixo."
65
+
66
+ destroy:
67
+ success:
68
+ title: "Sucesso!"
69
+ message: "O %{model_name} foi deletado com sucesso."
70
+
71
+ failure:
72
+ title: "Atenção!"
73
+ message: "Falha ao excluir %{model_name}."
74
+
51
75
  table:
52
76
  headers:
53
77
  id: "ID"
@@ -56,14 +80,5 @@ pt-BR:
56
80
  select:
57
81
  prompt: "- Selecione %{attribute_name} -"
58
82
 
59
- confirmation:
60
- title: "Você tem certeza?"
61
- delete: "Excluir"
62
- cancel: "Cancelar"
63
-
64
- ui:
65
- toggle_navigation: "Alternar naveção"
66
- toggle_sidebar: "Alternar barra lateral"
67
-
68
83
  format:
69
84
  blank: "Nenhum"
@@ -0,0 +1,18 @@
1
+ {
2
+ 'zh-CN' => {
3
+ date: {
4
+ formats: {
5
+ trestle_date: proc { |date| "%Y年%-m月%-d日" },
6
+ trestle_calendar: "%Y年%-m月%-d日"
7
+ }
8
+ },
9
+
10
+ time: {
11
+ formats: {
12
+ trestle_date: proc { |time| "%Y年%-m月%-d日" },
13
+ trestle_time: "%H:%M",
14
+ trestle_time_with_seconds: "%H:%M:%S"
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,94 @@
1
+ zh-CN:
2
+ trestle:
3
+ title: "Trestle Admin"
4
+ footer: "由 Trestle 强力驱动"
5
+ version: "版本"
6
+
7
+ helpers:
8
+ page_entries_info:
9
+ one_page:
10
+ display_entries:
11
+ zero: "没找到%{entry_name}"
12
+ one: "已显示 <strong>1</strong> 条%{entry_name}记录"
13
+ other: "已显示<strong>全部 %{count}</strong> 条%{entry_name}记录"
14
+
15
+ more_pages:
16
+ display_entries: "显示 %{entry_name} <strong>%{first}&nbsp;-&nbsp;%{last}</strong>,总共 <b>%{total} 条记录</b>"
17
+
18
+ onboarding:
19
+ welcome: "欢迎使用 Trestle"
20
+ no_admins: "要开始使用,请在 <code>app/admin</code> 里创建管理资源。"
21
+ no_template: "要自定义此模板,请创建 <code>%{path}</code>。"
22
+ no_form: "请定义一个表单块或者创建一个 <code>_form.html</code> 文件。"
23
+
24
+ ui:
25
+ toggle_navigation: "打开/隐藏导航"
26
+ toggle_sidebar: "打开/隐藏侧边栏"
27
+
28
+ dialog:
29
+ error: 无法完成该请求。
30
+
31
+ confirmation:
32
+ title: 真的要删除吗?
33
+ delete: 删除
34
+ cancel: 取消
35
+
36
+ admin:
37
+ titles:
38
+ index: "%{pluralized_model_name}列表"
39
+ new: "新建%{model_name}"
40
+ edit: "编辑%{model_name}"
41
+
42
+ buttons:
43
+ new: "新建%{model_name}"
44
+ save: "保存%{model_name}"
45
+ delete: "删除%{model_name}"
46
+ ok: "确定"
47
+
48
+ breadcrumbs:
49
+ home: "首页"
50
+
51
+ flash:
52
+ create:
53
+ success:
54
+ title: "成功!"
55
+ message: "%{lowercase_model_name}创建成功。"
56
+
57
+ failure:
58
+ title: "警告!"
59
+ message: "请修正以下错误。"
60
+
61
+ update:
62
+ success:
63
+ title: "成功!"
64
+ message: "%{lowercase_model_name}更新成功。"
65
+
66
+ failure:
67
+ title: "警告!"
68
+ message: "请修正以下错误。"
69
+
70
+ destroy:
71
+ success:
72
+ title: "成功!"
73
+ message: "%{lowercase_model_name}删除成功。"
74
+
75
+ failure:
76
+ title: "警告!"
77
+ message: "不能删除%{lowercase_model_name}。"
78
+
79
+ table:
80
+ headers:
81
+ id: "ID"
82
+
83
+ form:
84
+ select:
85
+ prompt: "- 选择%{attribute_name} -"
86
+
87
+ format:
88
+ blank: "无"
89
+
90
+ datepicker:
91
+ formats:
92
+ date: "Y年m月d日"
93
+ datetime: "Y年m月d日 H:i"
94
+ time: "H:i"
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'coveralls', require: false
5
+ gem 'simplecov', require: false
6
+
7
+ gem 'capybara'
8
+ gem 'capybara-selenium'
9
+ gem 'selenium-webdriver'
10
+ end
11
+
12
+ gem 'rails', '~> 5.2.0'
13
+
14
+ gemspec :path => "../"
@@ -133,10 +133,10 @@ module Trestle
133
133
  #
134
134
  # Returns a Kaminari-compatible scope corresponding to a single page.
135
135
  def paginate(collection, params)
136
- collection = Kaminari.paginate_array(collection.to_a) unless collection.respond_to?(:page)
136
+ collection = Kaminari.paginate_array(collection.to_a) unless collection.respond_to?(Kaminari.config.page_method_name)
137
137
  per_page = admin.pagination_options[:per]
138
138
 
139
- collection.page(params[:page]).per(per_page)
139
+ collection.public_send(Kaminari.config.page_method_name, params[:page]).per(per_page)
140
140
  end
141
141
 
142
142
  # Filters the submitted form parameters and returns a whitelisted attributes 'hash'
@@ -149,7 +149,7 @@ module Trestle
149
149
  #
150
150
  # Returns the permitted set of parameters as a ActionController::Parameters object.
151
151
  def permitted_params(params)
152
- params.require(admin.admin_name.singularize).permit!
152
+ params.require(admin.parameter_name).permit!
153
153
  end
154
154
 
155
155
  # Produces a human-readable name for a given attribute, applying I18n where appropriate.
data/lib/trestle/admin.rb CHANGED
@@ -46,13 +46,33 @@ module Trestle
46
46
  end
47
47
 
48
48
  def default_breadcrumb
49
- Breadcrumb.new(I18n.t("admin.breadcrumbs.#{admin_name}", default: admin_name.titleize), path)
49
+ Breadcrumb.new(human_admin_name, path)
50
50
  end
51
51
 
52
52
  def admin_name
53
53
  name.underscore.sub(/_admin$/, '')
54
54
  end
55
55
 
56
+ def i18n_key
57
+ admin_name
58
+ end
59
+
60
+ def human_admin_name
61
+ I18n.t("admin.breadcrumbs.#{i18n_key}", default: name.demodulize.underscore.sub(/_admin$/, '').titleize)
62
+ end
63
+
64
+ def translate(key, options={})
65
+ defaults = [:"admin.#{i18n_key}.#{key}", :"admin.#{key}"]
66
+ defaults << options[:default] if options[:default]
67
+
68
+ I18n.t(defaults.shift, options.merge(default: defaults))
69
+ end
70
+ alias t translate
71
+
72
+ def parameter_name
73
+ admin_name.singularize
74
+ end
75
+
56
76
  def route_name
57
77
  "#{admin_name.tr('/', '_')}_admin"
58
78
  end
@@ -65,7 +85,7 @@ module Trestle
65
85
  "#{name.underscore}/admin"
66
86
  end
67
87
 
68
- def path(action=:index, options={})
88
+ def path(action=root_action, options={})
69
89
  Engine.routes.url_for(options.merge(controller: controller_namespace, action: action, only_path: true))
70
90
  end
71
91
 
@@ -73,6 +93,10 @@ module Trestle
73
93
  [:index]
74
94
  end
75
95
 
96
+ def root_action
97
+ :index
98
+ end
99
+
76
100
  def routes
77
101
  admin = self
78
102
 
@@ -92,6 +116,10 @@ module Trestle
92
116
  def build(&block)
93
117
  Admin::Builder.build(self, &block)
94
118
  end
119
+
120
+ def validate!
121
+ # No validations by default. This can be overridden in subclasses.
122
+ end
95
123
  end
96
124
  end
97
125
  end
@@ -34,6 +34,9 @@ module Trestle
34
34
  controller.instance_variable_set("@admin", admin)
35
35
 
36
36
  admin.build(&block)
37
+ admin.validate!
38
+
39
+ admin
37
40
  end
38
41
 
39
42
  def menu(*args, &block)
@@ -45,12 +48,7 @@ module Trestle
45
48
  end
46
49
 
47
50
  def table(name_or_options={}, options={}, &block)
48
- if name_or_options.is_a?(Hash)
49
- name, options = :index, name_or_options.reverse_merge(admin: admin, sortable: true)
50
- else
51
- name = name_or_options
52
- end
53
-
51
+ name, options = normalize_table_options(name_or_options, options)
54
52
  admin.tables[name] = Table::Builder.build(options, &block)
55
53
  end
56
54
 
@@ -75,10 +73,22 @@ module Trestle
75
73
  def breadcrumb(label=nil, path=nil, &block)
76
74
  if block_given?
77
75
  @admin.breadcrumb = block
78
- else
76
+ elsif label
79
77
  @admin.breadcrumb = -> { Breadcrumb.new(label, path) }
78
+ else
79
+ @admin.breadcrumb = -> { false }
80
80
  end
81
81
  end
82
+
83
+ protected
84
+ def normalize_table_options(name, options)
85
+ if name.is_a?(Hash)
86
+ # Default index table
87
+ name, options = :index, name
88
+ end
89
+
90
+ [name, options]
91
+ end
82
92
  end
83
93
  end
84
94
  end
@@ -18,6 +18,8 @@ module Trestle
18
18
  new(obj)
19
19
  when Array
20
20
  new(*obj)
21
+ when NilClass, false
22
+ nil
21
23
  else
22
24
  raise ArgumentError, "Unable to cast #{obj.inspect} to Breadcrumb"
23
25
  end
@@ -27,7 +29,7 @@ module Trestle
27
29
  include Enumerable
28
30
 
29
31
  def initialize(breadcrumbs=[])
30
- @breadcrumbs = Array(breadcrumbs)
32
+ @breadcrumbs = Array(breadcrumbs).compact
31
33
  end
32
34
 
33
35
  def ==(other)