diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/link_helper.rb | 25 | ||||
-rw-r--r-- | app/helpers/table_helper.rb | 13 |
2 files changed, 38 insertions, 0 deletions
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 55e392b..ddb063e 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -1,5 +1,30 @@ module LinkHelper + Action = Struct.new(:target, :verb, :options) do + def to_partial_path; 'common/action'; end + def label; options[:label]; end + def class; verb; end + def url + case verb + when :show, :destroy then target + when :edit, :new then [verb, target] + end + end + + def html_options + if verb == :destroy + {method: :delete} + end + end + end + + def actions(target) + target.actions.map do |action| + Action.new target, action, + label: t(".#{action}", cascade: true) + end + end + # # markup for bootstrap button # diff --git a/app/helpers/table_helper.rb b/app/helpers/table_helper.rb new file mode 100644 index 0000000..16a7019 --- /dev/null +++ b/app/helpers/table_helper.rb @@ -0,0 +1,13 @@ +module TableHelper + + # we do the translation here so the .key lookup is relative + # to the partial the helper was called from. + def table(content, columns) + render 'common/table', + content: content, + columns: columns, + headers: columns.map {|h| t(".#{h}", cascading: true) }, + none: t('.none', cascading: true) + end + +end |