motion-prime/views/styles.rb in motion-prime-0.2.1 vs motion-prime/views/styles.rb in motion-prime-0.3.0

- old
+ new

@@ -5,24 +5,34 @@ def initialize(namespace = nil) @namespace = namespace end - def style(name, options = {}) - name = "#{@namespace}_#{name}".to_sym if @namespace - @@repo[name] ||= {} - if parent = options.delete(:parent) - parent ="#{@namespace}_#{parent}".to_sym if @namespace - @@repo[name].deep_merge! self.class.for(parent) + def style(*args) + 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 + + @@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) + end + @@repo[name].deep_merge! options end - @@repo[name].deep_merge! options end class << self include HasNormalizer - def define(namespace = nil, &block) - self.new(namespace).instance_eval(&block) + def define(*namespaces, &block) + Array.wrap(namespaces).each do |namespace| + self.new(namespace).instance_eval(&block) + end end def for(style_names) style_options = {} Array.wrap(style_names).each do |name| \ No newline at end of file