Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_button options for modal helper #161

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bh.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
# For development / Code coverage / Documentation
spec.add_development_dependency 'bundler', '~> 1.1'
spec.add_development_dependency 'rspec', '~> 3.1'
spec.add_development_dependency 'rake', '~> 10.3'
spec.add_development_dependency 'rake', '~> 11.1'
spec.add_development_dependency 'yard', '~> 0.8.7'
spec.add_development_dependency 'coveralls', '~> 0.8.13'
spec.add_development_dependency 'activemodel' # versioned in gemfiles/
Expand Down
5 changes: 5 additions & 0 deletions lib/bh/classes/modal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def caption
@options.fetch(:button, {}).fetch :caption, title
end

# @return [Boolean] whether to display button of the modal dialog.
def no_button
@options.fetch :no_button, false
end

# @return [#to_s] the title to display on top of the modal dialog.
def title
@options.fetch :title, 'Modal'
Expand Down
5 changes: 4 additions & 1 deletion lib/bh/helpers/modal_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Helpers
# Using this option is equivalent to passing the body as an argument.
# @option options [#to_s] :size the size of the modal. Can be `:large`
# (alias `:lg`) or `:small` (alias `:sm`).
# @option options [Boolean] :no_button (false) whether to display button
# @option options [Hash] :button the options for the toggle button.
# * :caption (#to_s) ('Modal') the caption of the toggle button.
# * :context (#to_s) (:default) the contextual alternative to apply to
Expand All @@ -37,14 +38,16 @@ module Helpers
# end
def modal(*args, &block)
modal = Bh::Modal.new self, *args, &block
modal.extract! :button, :size, :body, :title, :id
modal.extract! :button, :size, :body, :no_button, :title, :id

modal.extract_from :button, [:context, :size, :layout, :caption]
modal.append_class_to! :button, :btn
modal.append_class_to! :button, modal.button_context_class
modal.append_class_to! :button, modal.button_size_class
modal.merge! button: {caption: modal.caption}

modal.merge! no_button: modal.no_button

modal.append_class_to! :div, :'modal-dialog'
modal.append_class_to! :div, modal.dialog_size_class
modal.merge! div: {title: modal.title, id: modal.id}
Expand Down
2 changes: 1 addition & 1 deletion lib/bh/views/bh/_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<button class="<%= button[:class] %>" data-toggle="modal" data-target="#<%= div[:id] %>"><%= button[:caption] %></button>
<% unless no_button %><button class="<%= button[:class] %>" data-toggle="modal" data-target="#<%= div[:id] %>"><%= button[:caption] %></button><% end %>
<div class="modal fade" id="<%= div[:id] %>" tabindex="-1" role="dialog" aria-labelledby="label-<%= div[:id] %>" aria-hidden="true">
<div class="<%= div[:class] %>">
<div class="modal-content">
Expand Down