xass 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 143c53eb80a72aea9f75142dc77663eac1ab5022
4
- data.tar.gz: c6b4f1bb75b3652c131af148ddb295c483e943f2
3
+ metadata.gz: 2d8414b98758d82aeb2cbb007ff5a75c3235bd9b
4
+ data.tar.gz: 7a6901d2a61939efa3c1e9a0ae963ffeca57284c
5
5
  SHA512:
6
- metadata.gz: 6bff498350caa23e4c4c876d6016b0f83832343033159378deeb5b1b14120b3632216d490ea0e8c4a7f19a446fe17f6011b17d75e3afeef94fa2d600354393e1
7
- data.tar.gz: 6ea07a231e773a159a3e30a09522919a6b313eb3d7c84212792aeac8a5ade62e24d301431ad7b70ca0bdb88f9b7f826cd16843e6863de527a69a5217ab07780e
6
+ metadata.gz: 68f5cf3d0135b3d443d42dce4e4c87211b37602c69fd7578d0850dcce1e962bc15c29066ad8662d652171b54fd5f5c1137b38c95947e72d0aaccedc22bad13fb
7
+ data.tar.gz: abd363ab0915631ca0c08904fe8e15e9f28fb0b712443bbb92b558efdcf9f965a07f030d15ca1cb8abcf31f903677c9729be3eb35d618a8b7ffa1485058b5fd3
@@ -0,0 +1,7 @@
1
+ module Xass
2
+ class Railtie < Rails::Railtie
3
+ initializer "xass.view_helpers" do
4
+ ActionView::Base.send :include, ViewHelpers
5
+ end
6
+ end
7
+ end
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'xass'
3
- s.version = '0.1.3'
3
+ s.version = '0.1.4'
4
4
  s.authors = ['Tetsuri Moriya']
5
5
  s.email = ['tetsuri.moriya@gmail.com']
6
6
  s.summary = 'Sass namespace extension'
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.3
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