diff options
| author | Teddy Wing | 2018-01-23 14:45:47 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2018-01-23 14:45:47 +0100 | 
| commit | 01c66e361fcf800a973606310549f342c89727a9 (patch) | |
| tree | f3da23ff99181e9316db304d6e4f20fb0731359b | |
| parent | 571b42b20f483b929453452b420d61e20834ffa8 (diff) | |
| download | chouette-core-01c66e361fcf800a973606310549f342c89727a9.tar.bz2 | |
AF83::Decorator::Link: Change #class? to #default_class
Instead of checking for an existing class and then setting the class,
provide a method to set a default class when one hasn't been defined.
This does effectively the same thing but moves the condition inside the
method.
Thanks Johan for the suggestion!
Refs #5586
| -rw-r--r-- | app/views/layouts/navigation/_page_header.html.slim | 6 | ||||
| -rw-r--r-- | lib/af83/decorator/link.rb | 7 | 
2 files changed, 7 insertions, 6 deletions
| diff --git a/app/views/layouts/navigation/_page_header.html.slim b/app/views/layouts/navigation/_page_header.html.slim index 23bc64db0..cd4d41793 100644 --- a/app/views/layouts/navigation/_page_header.html.slim +++ b/app/views/layouts/navigation/_page_header.html.slim @@ -24,15 +24,13 @@            - if action_links&.primary&.any?              - action_links.primary.each do |link|                = link.to_html do |l| -                - if !l.class? -                  - l.class "btn btn-default #{l.disabled ? "disabled" : ""}" +                - l.default_class "btn btn-default #{l.disabled ? "disabled" : ""}"      - if action_links&.secondary&.any?        .row.mb-sm          .col-lg-12.text-right            - action_links.secondary.each do |link|              = link.to_html do |l| -              - if !l.class? -                - l.class "btn btn-primary #{l.disabled ? "disabled" : ""}" +              - l.default_class "btn btn-primary #{l.disabled ? "disabled" : ""}"      - if content_for? :page_header_content        = yield :page_header_content diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index 10e6091aa..fd50069fe 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -25,8 +25,11 @@ class AF83::Decorator::Link      link_class args    end -  def class? -    @options[:link_class] && !@options[:link_class].empty? +  def default_class *args +    has_class = @options[:link_class] && !@options[:link_class].empty? +    return if has_class + +    self.class args    end    def method_missing name, *args, &block | 
