Skip to content

Instantly share code, notes, and snippets.

@gt-sdi
Forked from isc/README.markdown
Last active October 13, 2015 20:57

Revisions

  1. gt-sdi revised this gist Jan 5, 2013. 3 changed files with 9 additions and 8 deletions.
    5 changes: 4 additions & 1 deletion README.markdown
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,10 @@ In your Gemfile:
    `accordion` method options :

    - `:accordion_id` : when you want more than one accordion on the same page.
    - `:open` : when you want the first pane to be open on load.

    `pane` method options :

    - `:open` : when you want that pane to be open on load.

    ### Tabs helper:

    6 changes: 2 additions & 4 deletions accordion_helper.rb
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,12 @@ class AccordionBuilder
    delegate :capture, :content_tag, :link_to, :to => :parent

    def initialize opts, parent
    @first = true
    @parent = parent
    @opts = opts
    end

    def pane title, &block
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    def pane title, options = {}, &block
    css_class = options[:open] ? 'in' : ''
    content_tag :div, :class => 'accordion-group' do
    heading = content_tag :div, :class => 'accordion-heading' do
    link_to title, "##{title.parameterize}_pane", :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    6 changes: 3 additions & 3 deletions bootstrap-components-helpers.gemspec
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    Gem::Specification.new do |s|
    s.name = 'bootstrap-components-helpers'
    s.summary = 'Accordion view helper for Twitter Bootstrap'
    s.description = 'A micro gem providing an accordion view helper that generates the proper markup for Twitter Bootstrap'
    s.version = '0.0.1'
    s.description = 'A micro gem providing an accordion view helper that generates the proper markup for Twitter Bootstrap. Modified by Graham to specify open accordion pane right on pane'
    s.version = '0.0.2'
    s.platform = Gem::Platform::RUBY

    s.files = ['bootstrap-components-helpers.rb', 'accordion_helper.rb', 'tabs_helper.rb']
    s.require_path = '.'

    s.author = 'Ivan Schneider'
    s.authors = ['Ivan Schneider', 'Graham Torn']
    s.email = '[email protected]'
    s.homepage = 'https://dbinsights.herokuapp.com'

  2. gt-sdi revised this gist Dec 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.markdown
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ Provides an `accordion` helper and a `tabs` helper

    In your Gemfile:

    gem 'bootstrap-components-helpers', :git => 'git://gist.github.com/2117187.git'
    gem 'bootstrap-components-helpers', :git => 'git://gist.github.com/4254678.git'

    ### Accordion helper:

  3. @isc isc revised this gist Mar 26, 2012. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions accordion_helper.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ def accordion opts = {}
    class AccordionBuilder

    attr_reader :parent
    delegate :capture, :to => :parent
    delegate :capture, :content_tag, :link_to, :to => :parent

    def initialize opts, parent
    @first = true
    @@ -20,20 +20,20 @@ def initialize opts, parent
    end

    def pane title, &block
    b = Builder::XmlMarkup.new
    b.div :class => 'accordion-group' do
    b.div :class => 'accordion-heading' do
    b.a title, :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    :'data-parent' => "##{@opts[:accordion_id]}", :href => "##{title.parameterize}_pane"
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    content_tag :div, :class => 'accordion-group' do
    heading = content_tag :div, :class => 'accordion-heading' do
    link_to title, "##{title.parameterize}_pane", :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    :'data-parent' => "##{@opts[:accordion_id]}"
    end
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    b.div :class => "accordion-body collapse #{css_class}", :id => "#{title.parameterize}_pane" do
    b.div :class => 'accordion-inner' do
    b << capture(&block)
    body = content_tag :div, :class => "accordion-body collapse #{css_class}", :id => "#{title.parameterize}_pane" do
    content_tag :div, :class => 'accordion-inner' do
    capture(&block)
    end
    end
    end.html_safe
    heading + body
    end
    end
    end
    end
  4. @isc isc revised this gist Mar 25, 2012. 2 changed files with 7 additions and 4 deletions.
    7 changes: 4 additions & 3 deletions README.markdown
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,8 @@ In your Gemfile:

    `accordion` method options :

    - `:accordion_id` : when you want more than one accordion on the same page
    - `:open` : when you want the first pane to be open on load
    - `:accordion_id` : when you want more than one accordion on the same page.
    - `:open` : when you want the first pane to be open on load.

    ### Tabs helper:

    @@ -29,4 +29,5 @@ In your Gemfile:
    `tabs` method options :

    - `:direction` : to control the positioning of the tabs. Valid values are below, left, right and above (default).
    - `:direction` : to control the positioning of the tabs. Valid values are `below`, `left`, `right` and `above` (default is `above`).
    - `:style` : `tabs` or `pills` (default is `tabs`).
    4 changes: 3 additions & 1 deletion tabs_helper.rb
    Original file line number Diff line number Diff line change
    @@ -2,9 +2,10 @@ module BootstrapComponentsHelpers
    module TabsHelper
    def tabs opts = {}
    opts[:direction] ||= 'above'
    opts[:style] ||= 'tabs'
    builder = TabsBuilder.new self
    yield builder
    tabs = content_tag(:ul, builder.pane_handles.join("\n").html_safe, :class => 'nav nav-tabs')
    tabs = content_tag(:ul, builder.pane_handles.join("\n").html_safe, :class => "nav nav-#{opts[:style]}")
    contents = content_tag(:div, builder.pane_contents.join("\n").html_safe, :class => 'tab-content')
    css_direction = "tabs-#{opts[:direction]}" unless opts[:direction] == 'above'
    content_tag :div, :class => "tabbable #{css_direction}" do
    @@ -39,6 +40,7 @@ def pane title, &block
    end

    end

    end
    end

  5. @isc isc revised this gist Mar 25, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bootstrap-components-helpers.gemspec
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Gem::Specification.new do |s|
    s.version = '0.0.1'
    s.platform = Gem::Platform::RUBY

    s.files = ['bootstrap-components-helpers.rb', 'accordion-helper.rb', 'tabs-helper.rb']
    s.files = ['bootstrap-components-helpers.rb', 'accordion_helper.rb', 'tabs_helper.rb']
    s.require_path = '.'

    s.author = 'Ivan Schneider'
  6. @isc isc revised this gist Mar 25, 2012. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions tabs_helper.rb
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ module BootstrapComponentsHelpers
    module TabsHelper
    def tabs opts = {}
    opts[:direction] ||= 'above'
    builder = TabsBuilder.new opts, self
    builder = TabsBuilder.new self
    yield builder
    tabs = content_tag(:ul, builder.pane_handles.join("\n").html_safe, :class => 'nav nav-tabs')
    contents = content_tag(:div, builder.pane_contents.join("\n").html_safe, :class => 'tab-content')
    @@ -21,10 +21,9 @@ class TabsBuilder
    attr_reader :parent, :pane_contents, :pane_handles
    delegate :capture, :content_tag, :to => :parent

    def initialize opts, parent
    def initialize parent
    @first = true
    @parent = parent
    @opts = opts
    @pane_handles = []
    @pane_contents = []
    end
  7. @isc isc revised this gist Mar 25, 2012. 5 changed files with 108 additions and 46 deletions.
    20 changes: 17 additions & 3 deletions README.markdown
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,12 @@
    #
    ## Twitter Bootstrap Components Helper

    Provides an `accordion` helper and a `tabs` helper

    In your Gemfile:

    gem 'bootstrap-components-helpers', :git => 'git://gist.github.com/2117187.git'

    In your views:
    ### Accordion helper:

    = accordion do |accordion|
    = accordion.pane 'My first pane' do
    @@ -15,4 +17,16 @@ In your views:
    `accordion` method options :

    - `:accordion_id` : when you want more than one accordion on the same page
    - `:open` : when you want the first pane to be open on load
    - `:open` : when you want the first pane to be open on load

    ### Tabs helper:

    = tabs do |tabs|
    - tabs.pane 'My first pane' do
    = render partial: 'my_first_pane'
    - tabs.pane 'My second pane' do
    = render partial: 'my_second_pane'
    `tabs` method options :

    - `:direction` : to control the positioning of the tabs. Valid values are below, left, right and above (default).
    42 changes: 42 additions & 0 deletions accordion_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    module BootstrapComponentsHelpers
    module AccordionHelper
    def accordion opts = {}
    opts[:accordion_id] ||= 'accordion'
    builder = AccordionBuilder.new opts, self
    content_tag :div, :class => 'accordion', :id => opts[:accordion_id] do
    yield builder
    end
    end

    class AccordionBuilder

    attr_reader :parent
    delegate :capture, :to => :parent

    def initialize opts, parent
    @first = true
    @parent = parent
    @opts = opts
    end

    def pane title, &block
    b = Builder::XmlMarkup.new
    b.div :class => 'accordion-group' do
    b.div :class => 'accordion-heading' do
    b.a title, :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    :'data-parent' => "##{@opts[:accordion_id]}", :href => "##{title.parameterize}_pane"
    end
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    b.div :class => "accordion-body collapse #{css_class}", :id => "#{title.parameterize}_pane" do
    b.div :class => 'accordion-inner' do
    b << capture(&block)
    end
    end
    end.html_safe
    end
    end
    end
    end

    ActionView::Base.send :include, BootstrapComponentsHelpers::AccordionHelper
    2 changes: 1 addition & 1 deletion bootstrap-components-helpers.gemspec
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Gem::Specification.new do |s|
    s.version = '0.0.1'
    s.platform = Gem::Platform::RUBY

    s.files = ['bootstrap-components-helpers.rb']
    s.files = ['bootstrap-components-helpers.rb', 'accordion-helper.rb', 'tabs-helper.rb']
    s.require_path = '.'

    s.author = 'Ivan Schneider'
    44 changes: 2 additions & 42 deletions bootstrap-components-helpers.rb
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,2 @@
    module BootstrapComponentsHelpers
    module AccordionHelper
    def accordion opts = {}
    opts[:accordion_id] ||= 'accordion'
    builder = AccordionBuilder.new opts, self
    content_tag :div, :class => 'accordion', :id => opts[:accordion_id] do
    yield builder
    end
    end

    class AccordionBuilder

    attr_reader :parent
    delegate :capture, :to => :parent

    def initialize opts, parent
    @first = true
    @parent = parent
    @opts = opts
    end

    def pane title, &block
    b = Builder::XmlMarkup.new
    b.div :class => 'accordion-group' do
    b.div :class => 'accordion-heading' do
    b.a title, :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    :'data-parent' => "##{@opts[:accordion_id]}", :href => "##{title.parameterize}_pane"
    end
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    b.div :class => "accordion-body collapse #{css_class}", :id => "#{title.parameterize}_pane" do
    b.div :class => 'accordion-inner' do
    b << capture(&block)
    end
    end
    end.html_safe
    end
    end
    end
    end

    ActionView::Base.send :include, BootstrapComponentsHelpers::AccordionHelper
    require 'accordion_helper'
    require 'tabs_helper'
    46 changes: 46 additions & 0 deletions tabs_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    module BootstrapComponentsHelpers
    module TabsHelper
    def tabs opts = {}
    opts[:direction] ||= 'above'
    builder = TabsBuilder.new opts, self
    yield builder
    tabs = content_tag(:ul, builder.pane_handles.join("\n").html_safe, :class => 'nav nav-tabs')
    contents = content_tag(:div, builder.pane_contents.join("\n").html_safe, :class => 'tab-content')
    css_direction = "tabs-#{opts[:direction]}" unless opts[:direction] == 'above'
    content_tag :div, :class => "tabbable #{css_direction}" do
    if opts[:direction] == 'below'
    contents + tabs
    else
    tabs + contents
    end
    end
    end

    class TabsBuilder

    attr_reader :parent, :pane_contents, :pane_handles
    delegate :capture, :content_tag, :to => :parent

    def initialize opts, parent
    @first = true
    @parent = parent
    @opts = opts
    @pane_handles = []
    @pane_contents = []
    end

    def pane title, &block
    css_class, @first = 'active', false if @first
    link = content_tag(:a, title, :'data-toggle' => 'tab', :href => "##{title.parameterize}_tab")
    @pane_handles << content_tag(:li, link, :class => css_class)
    @pane_contents << (content_tag :div, :class => "tab-pane #{css_class}", :id => "#{title.parameterize}_tab" do
    capture(&block)
    end)
    nil
    end

    end
    end
    end

    ActionView::Base.send :include, BootstrapComponentsHelpers::TabsHelper
  8. @isc isc renamed this gist Mar 19, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @isc isc revised this gist Mar 19, 2012. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,18 @@
    #

    Description and usage:
    In your Gemfile:

    gem 'bootstrap-components-helpers', :git => 'git://gist.github.com/2117187.git'

    In your views:

    = accordion do |accordion|
    = accordion.pane 'My first pane' do
    = render partial: 'my_first_pane'
    = accordion.pane 'My second pane' do
    = render partial: 'my_second_pane'

    `accordion` method options :

    - `:accordion_id` : when you want more than one accordion on the same page
    - `:open` : when you want the first pane to be open on load
  10. @isc isc revised this gist Mar 19, 2012. 3 changed files with 2 additions and 12 deletions.
    12 changes: 1 addition & 11 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,5 @@

    Description and usage:

    require ''
    .new
    gem 'bootstrap-components-helpers', :git => 'git://gist.github.com/2117187.git'

    # Running the tests

    Install the rspec gem

    gem install rspec

    Run the spec

    rspec _spec.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Gem::Specification.new do |s|
    s.version = '0.0.1'
    s.platform = Gem::Platform::RUBY

    s.files = ['bootstrap_components_helpers.rb']
    s.files = ['bootstrap-components-helpers.rb']
    s.require_path = '.'

    s.author = 'Ivan Schneider'
  11. @isc isc revised this gist Mar 19, 2012. 3 changed files with 75 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,16 @@
    Dummy content
    #

    Description and usage:

    require ''
    .new

    # Running the tests

    Install the rspec gem

    gem install rspec

    Run the spec

    rspec _spec.rb
    17 changes: 17 additions & 0 deletions bootstrap_components_helpers.gemspec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    Gem::Specification.new do |s|
    s.name = 'bootstrap-components-helpers'
    s.summary = 'Accordion view helper for Twitter Bootstrap'
    s.description = 'A micro gem providing an accordion view helper that generates the proper markup for Twitter Bootstrap'
    s.version = '0.0.1'
    s.platform = Gem::Platform::RUBY

    s.files = ['bootstrap_components_helpers.rb']
    s.require_path = '.'

    s.author = 'Ivan Schneider'
    s.email = '[email protected]'
    s.homepage = 'https://dbinsights.herokuapp.com'

    # s.test_file = '_spec.rb'
    # s.add_development_dependency('rspec', ["~> 2.8"])
    end
    42 changes: 42 additions & 0 deletions bootstrap_components_helpers.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    module BootstrapComponentsHelpers
    module AccordionHelper
    def accordion opts = {}
    opts[:accordion_id] ||= 'accordion'
    builder = AccordionBuilder.new opts, self
    content_tag :div, :class => 'accordion', :id => opts[:accordion_id] do
    yield builder
    end
    end

    class AccordionBuilder

    attr_reader :parent
    delegate :capture, :to => :parent

    def initialize opts, parent
    @first = true
    @parent = parent
    @opts = opts
    end

    def pane title, &block
    b = Builder::XmlMarkup.new
    b.div :class => 'accordion-group' do
    b.div :class => 'accordion-heading' do
    b.a title, :class => 'accordion-toggle', :'data-toggle' => 'collapse',
    :'data-parent' => "##{@opts[:accordion_id]}", :href => "##{title.parameterize}_pane"
    end
    css_class = (@first && @opts[:open]) ? 'in' : ''
    @first = false
    b.div :class => "accordion-body collapse #{css_class}", :id => "#{title.parameterize}_pane" do
    b.div :class => 'accordion-inner' do
    b << capture(&block)
    end
    end
    end.html_safe
    end
    end
    end
    end

    ActionView::Base.send :include, BootstrapComponentsHelpers::AccordionHelper
  12. @isc isc created this gist Mar 19, 2012.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    Dummy content