motion-prime/views/styles.rb in motion-prime-0.3.0 vs motion-prime/views/styles.rb in motion-prime-0.3.1
- old
+ new
@@ -5,24 +5,31 @@
def initialize(namespace = nil)
@namespace = namespace
end
- def style(*args)
+ def style(*args, &block)
names = Array.wrap(args)
options = names.pop if args.last.is_a?(Hash)
- raise "No style rules specified for `#{names.join(', ')}`. Namespace: `#{@namespace}`" unless options
- names.each do |name|
- name = "#{@namespace}_#{name}".to_sym if @namespace
+ if block_given?
+ raise "Only style names are available for nested styles, received: `#{args.inspect}`. Namespace: `#{@namespace}`" if options.present?
+ names.each do |name|
+ puts namespace = [@namespace, name].compact.join('_')
+ self.class.new(namespace).instance_eval(&block)
+ end
+ else
+ raise "No style rules specified for `#{names.join(', ')}`. Namespace: `#{@namespace}`" unless options
+ parent = options.delete(:parent)
+ namespace = options.delete(:parent_namspace) || @namespace
+ parent ="#{namespace}_#{parent}".to_sym if namespace
- @@repo[name] ||= {}
- if parent = options.delete(:parent)
- namespace = options.delete(:parent_namspace) || @namespace
- parent ="#{namespace}_#{parent}".to_sym if namespace
- @@repo[name].deep_merge! self.class.for(parent)
+ names.each do |name|
+ name = "#{@namespace}_#{name}".to_sym if @namespace
+ @@repo[name] ||= {}
+ @@repo[name].deep_merge!(self.class.for(parent)) if parent
+ @@repo[name].deep_merge! options
end
- @@repo[name].deep_merge! options
end
end
class << self
include HasNormalizer
\ No newline at end of file