xass 0.1.8 → 0.1.9
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/view_helpers.rb +69 -22
- data/lib/xass.rb +17 -6
- data/xass.gemspec +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a50e4ca63afeb3d5131cdf4cdd811b930b8ea8
|
4
|
+
data.tar.gz: 8bddf67014de48ec254ddef2faed3155305b508d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e3e98cd4b5b969ffba2c7fe4ab8b4e1ec4f8e20c0ee46b492b53909a9616f26a55214b6bdf05b28599d6d80abc37285cece2035a05b631a18edd7047771690f
|
7
|
+
data.tar.gz: 1dc7a5bd0f6eb59c0dba2de7213501ea292e879d314876592cc21cff2996fecc6f88ced0063dcfd0e9d576e551cb77366d71a03fc122d0b4bd9a8d1e53052f76
|
data/lib/xass/view_helpers.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
module Xass
|
2
2
|
module ViewHelpers
|
3
3
|
def namespace(*names, reset: false, &block)
|
4
|
-
|
5
|
-
|
6
|
-
@namespaces = [names]
|
7
|
-
else
|
8
|
-
@namespaces = nss + [names]
|
9
|
-
end
|
4
|
+
n = reset ? names : namespace_stack.last + names
|
5
|
+
namespace_stack.push(n)
|
10
6
|
res = capture(&block)
|
11
|
-
|
12
|
-
res
|
7
|
+
namespace_stack.pop
|
8
|
+
node = Nokogiri::HTML(res)
|
9
|
+
process_namespace_classes(node, n)
|
10
|
+
node.to_html.html_safe
|
13
11
|
end
|
14
12
|
|
15
13
|
def namespace!(*names, &block)
|
@@ -17,8 +15,8 @@ module Xass
|
|
17
15
|
end
|
18
16
|
|
19
17
|
def namespace_with_root(*names, tag: :div, attrs: {}, reset: false, &block)
|
20
|
-
nss = reset ? [] :
|
21
|
-
content_tag(tag, block ? namespace(*names, reset: reset, &block) : '', attrs_with_additional_class(attrs, ns_root!(*(nss
|
18
|
+
nss = reset ? [] : namespace_stack.last
|
19
|
+
content_tag(tag, block ? namespace(*names, reset: reset, &block) : '', attrs_with_additional_class(attrs, ns_root!(*(nss + names))))
|
22
20
|
end
|
23
21
|
|
24
22
|
def namespace_with_root!(*names, tag: :div, attrs: {}, &block)
|
@@ -31,18 +29,14 @@ module Xass
|
|
31
29
|
content_tag(_tag, block ? capture(&block) : '', attrs_with_additional_name(_attrs, name))
|
32
30
|
end
|
33
31
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
html_options ||= {}
|
40
|
-
link_to(_name, options, attrs_with_additional_name(html_options, name), &block)
|
41
|
-
end
|
32
|
+
def ns_content(name = :content, _tag = nil, _attrs = nil, tag: :div, attrs: {}, &block)
|
33
|
+
_tag ||= tag
|
34
|
+
_attrs ||= attrs
|
35
|
+
ns_wrap(name, tag: _tag, attrs: _attrs, &block)
|
42
36
|
end
|
43
37
|
|
44
38
|
def ns_root(*names)
|
45
|
-
ns_root!(*(
|
39
|
+
ns_root!(*(namespace_stack.last + names))
|
46
40
|
end
|
47
41
|
|
48
42
|
def ns_root!(*names)
|
@@ -50,17 +44,35 @@ module Xass
|
|
50
44
|
end
|
51
45
|
|
52
46
|
def ns(*names)
|
53
|
-
|
47
|
+
ns!(*(namespace_stack.last + names))
|
54
48
|
end
|
55
49
|
|
56
50
|
def ns!(*names)
|
57
51
|
"#{ns_root!(*names[0...-1])}___#{names[-1]}"
|
58
52
|
end
|
59
53
|
|
54
|
+
def ns_link_to(name, _name = nil, options = nil, html_options = nil, &block)
|
55
|
+
if block
|
56
|
+
options ||= {}
|
57
|
+
link_to(_name, attrs_with_additional_name(options, name), &block)
|
58
|
+
else
|
59
|
+
html_options ||= {}
|
60
|
+
link_to(_name, options, attrs_with_additional_name(html_options, name), &block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
alias :dns :namespace
|
65
|
+
alias :dns! :namespace!
|
66
|
+
alias :dnsr :namespace_with_root
|
67
|
+
alias :dnsr! :namespace_with_root!
|
68
|
+
alias :nsr :ns_root
|
69
|
+
alias :nsr! :ns_root!
|
70
|
+
alias :nsc :ns_content
|
71
|
+
|
60
72
|
private
|
61
73
|
|
62
|
-
def
|
63
|
-
@
|
74
|
+
def namespace_stack
|
75
|
+
@namespace_stack ||= [[]]
|
64
76
|
end
|
65
77
|
|
66
78
|
def attrs_with_additional_class(attrs, klass)
|
@@ -72,5 +84,40 @@ module Xass
|
|
72
84
|
def attrs_with_additional_name(attrs, name)
|
73
85
|
attrs_with_additional_class(attrs, ns(name))
|
74
86
|
end
|
87
|
+
|
88
|
+
def process_namespace_classes(node, n)
|
89
|
+
unless node['class'].blank?
|
90
|
+
node['class'] = node['class'].split(/ +/).map { |c|
|
91
|
+
if c.start_with?('ns-')
|
92
|
+
ns!(*n, *c[3..-1].split('--'))
|
93
|
+
elsif c.start_with?('nsb-')
|
94
|
+
ns!(*c[4..-1].split('--'))
|
95
|
+
elsif c.start_with?('dns-')
|
96
|
+
n = n + c[4..-1].split('--')
|
97
|
+
''
|
98
|
+
elsif c.start_with?('dnsb-')
|
99
|
+
n = c[5..-1].split('--')
|
100
|
+
''
|
101
|
+
elsif c == 'nsr'
|
102
|
+
nsr!(*n)
|
103
|
+
elsif c.start_with?('nsr-')
|
104
|
+
nsr!(*n, *c[4..-1].split('--'))
|
105
|
+
elsif c.start_with?('nsrb-')
|
106
|
+
nsr!(*c[5..-1].split('--'))
|
107
|
+
elsif c.start_with?('dnsr-')
|
108
|
+
n = n + c[5..-1].split('--')
|
109
|
+
nsr!(*n)
|
110
|
+
elsif c.start_with?('dnsrb-')
|
111
|
+
n = c[6..-1].split('--')
|
112
|
+
nsr!(*n)
|
113
|
+
else
|
114
|
+
c
|
115
|
+
end
|
116
|
+
}.join(' ')
|
117
|
+
end
|
118
|
+
node.children.each do |c|
|
119
|
+
process_namespace_classes(c, n)
|
120
|
+
end
|
121
|
+
end
|
75
122
|
end
|
76
123
|
end
|
data/lib/xass.rb
CHANGED
@@ -25,8 +25,8 @@ module Sass::Tree
|
|
25
25
|
trace_node = Sass::Tree::TraceNode.from_node(node.name, node)
|
26
26
|
with_environment(env) {
|
27
27
|
trace_node.children = mixin.tree.map {|c|
|
28
|
-
d = c.
|
29
|
-
d
|
28
|
+
d = c.deep_copy
|
29
|
+
xass_recursive_set_filename(d, node.filename)
|
30
30
|
visit(d)
|
31
31
|
}.flatten
|
32
32
|
}
|
@@ -41,6 +41,13 @@ module Sass::Tree
|
|
41
41
|
ensure
|
42
42
|
@stack.pop unless include_loop
|
43
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def xass_recursive_set_filename(node, filename)
|
48
|
+
node.filename = filename
|
49
|
+
node.children.each { |x| xass_recursive_set_filename(x, filename) }
|
50
|
+
end
|
44
51
|
end
|
45
52
|
|
46
53
|
class RootNode
|
@@ -50,9 +57,12 @@ module Sass::Tree
|
|
50
57
|
old_render.split('/*').map { |x|
|
51
58
|
next x unless x.match(/^ line [0-9]+, /)
|
52
59
|
a, b = x.split("\n", 2)
|
53
|
-
m = a.match(
|
54
|
-
|
55
|
-
|
60
|
+
m = a.match(/#{Rails.root}\/app\/assets\/stylesheets\/([^. ]+)\./)
|
61
|
+
d = "#{a}\n#{b}"
|
62
|
+
next d unless m
|
63
|
+
p = class_prefix(m[1])
|
64
|
+
next d unless p
|
65
|
+
selector = class_replaced_selector(b.split("\n")[0].strip[0...-1].strip, p)
|
56
66
|
"#{a}\n#{selector} {\n#{b.split("\n", 2)[1]}"
|
57
67
|
}.join('/*')
|
58
68
|
end
|
@@ -68,7 +78,8 @@ module Sass::Tree
|
|
68
78
|
def class_prefix(name)
|
69
79
|
names = name.split('/')
|
70
80
|
names = names[1..(names.index { |x| x.start_with?('!') } || -1)]
|
71
|
-
names.join('__')
|
81
|
+
p = names.join('__')
|
82
|
+
p.empty? ? nil : p
|
72
83
|
end
|
73
84
|
|
74
85
|
def replace_class(doc, class_prefix)
|
data/xass.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tetsuri Moriya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -112,4 +112,3 @@ signing_key:
|
|
112
112
|
specification_version: 4
|
113
113
|
summary: Sass namespace extension
|
114
114
|
test_files: []
|
115
|
-
has_rdoc:
|