xass 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/xass/railtie.rb +7 -0
 - data/lib/xass/view_helpers.rb +68 -0
 - data/xass.gemspec +1 -1
 - metadata +3 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2d8414b98758d82aeb2cbb007ff5a75c3235bd9b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7a6901d2a61939efa3c1e9a0ae963ffeca57284c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 68f5cf3d0135b3d443d42dce4e4c87211b37602c69fd7578d0850dcce1e962bc15c29066ad8662d652171b54fd5f5c1137b38c95947e72d0aaccedc22bad13fb
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: abd363ab0915631ca0c08904fe8e15e9f28fb0b712443bbb92b558efdcf9f965a07f030d15ca1cb8abcf31f903677c9729be3eb35d618a8b7ffa1485058b5fd3
         
     | 
    
        data/lib/xass/railtie.rb
    ADDED
    
    
| 
         @@ -0,0 +1,68 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Xass
         
     | 
| 
      
 2 
     | 
    
         
            +
              module ViewHelpers
         
     | 
| 
      
 3 
     | 
    
         
            +
                def namespace(*names, reset: false, &block)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  nss = namespaces
         
     | 
| 
      
 5 
     | 
    
         
            +
                  if reset
         
     | 
| 
      
 6 
     | 
    
         
            +
                    @namespaces = [names]
         
     | 
| 
      
 7 
     | 
    
         
            +
                  else
         
     | 
| 
      
 8 
     | 
    
         
            +
                    @namespaces = nss + [names]
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
                  res = capture(&block)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @namespaces = nss
         
     | 
| 
      
 12 
     | 
    
         
            +
                  res
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def namespace!(*names, &block)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  namespace(*names, reset: true, &block)
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def namespace_with_root(*names, tag: :div, attrs: {}, reset: false, &block)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  nss = reset ? [] : namespaces
         
     | 
| 
      
 21 
     | 
    
         
            +
                  content_tag(tag, namespace(*names, reset: reset, &block), attrs_with_additional_class(attrs, ns_root(nss + [names])))
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def namespace_with_root!(*names, tag: :div, attrs: {}, &block)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  namespace_with_root(*names, tag: tag, attrs: attrs, reset: true, &block)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def ns_wrap(name = :wrap, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  _tag ||= tag
         
     | 
| 
      
 30 
     | 
    
         
            +
                  _attrs ||= attrs
         
     | 
| 
      
 31 
     | 
    
         
            +
                  content_tag(_tag, block ? capture(&block) : '', attrs_with_additional_name(_attrs, name))
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def ns_link_to(name, _name = nil, options = nil, html_options = nil, &block)
         
     | 
| 
      
 35 
     | 
    
         
            +
                  if block
         
     | 
| 
      
 36 
     | 
    
         
            +
                    options ||= {}
         
     | 
| 
      
 37 
     | 
    
         
            +
                    link_to(_name, attrs_with_additional_name(options, name), &block)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  else
         
     | 
| 
      
 39 
     | 
    
         
            +
                    html_options ||= {}
         
     | 
| 
      
 40 
     | 
    
         
            +
                    link_to(_name, options, attrs_with_additional_name(html_options, name), &block)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def ns_root(nss = namespaces)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  nss.flatten.map(&:to_s).join('__')
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                def ns(name)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  "#{ns_root}___#{name}"
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                private
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def namespaces
         
     | 
| 
      
 55 
     | 
    
         
            +
                  @namespaces ||= []
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                def attrs_with_additional_class(attrs, klass)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  attrs.symbolize_keys!
         
     | 
| 
      
 60 
     | 
    
         
            +
                  attrs[:class] = attrs[:class].blank? ? klass : "#{attrs[:class]} #{klass}"
         
     | 
| 
      
 61 
     | 
    
         
            +
                  attrs
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                def attrs_with_additional_name(attrs, name)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  attrs_with_additional_class(attrs, ns(name))
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
            end
         
     | 
    
        data/xass.gemspec
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: xass
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Tetsuri Moriya
         
     | 
| 
         @@ -79,6 +79,8 @@ files: 
     | 
|
| 
       79 
79 
     | 
    
         
             
            - README.md
         
     | 
| 
       80 
80 
     | 
    
         
             
            - lib/initialize.rb
         
     | 
| 
       81 
81 
     | 
    
         
             
            - lib/xass.rb
         
     | 
| 
      
 82 
     | 
    
         
            +
            - lib/xass/railtie.rb
         
     | 
| 
      
 83 
     | 
    
         
            +
            - lib/xass/view_helpers.rb
         
     | 
| 
       82 
84 
     | 
    
         
             
            - spec/secrets.yml
         
     | 
| 
       83 
85 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       84 
86 
     | 
    
         
             
            - spec/test_spec.rb
         
     |