lib/bemer/entity_builder.rb in bemer-0.1.0 vs lib/bemer/entity_builder.rb in bemer-0.2.0

- old
+ new

@@ -1,19 +1,19 @@ # frozen_string_literal: true require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/hash/deep_merge' +require 'active_support/core_ext/string/filters' module Bemer class EntityBuilder < Entity def attrs attributes = Hash[super] attributes[:class] = cls return attributes unless bem? - attributes.deep_merge!(js) + attributes.merge!(js) end def attrs=(new_attrs, save = true) new_attrs = build_attrs(new_attrs) @@ -34,20 +34,16 @@ def bem_cascade bem_cascade_via_option? ? super : true end - def bem_cascade=(new_bem_cascade, save = true) - save ? @bem_cascade = new_bem_cascade : new_bem_cascade - end - def cls return super unless bem? js_class = 'i-bem' if @js.present? && bem_class.present? - [bem_class, mods, mix, super, js_class].reject(&:blank?) + [bem_class, mods, mix, super, js_class].join(' ').squish end def cls=(new_cls, save = true) new_cls = build_css_classes(new_cls) @@ -59,12 +55,12 @@ end def js return {} if @js.blank? || bem_class.blank? - attrs = @js.instance_of?(TrueClass) ? {} : super + js_attrs = @js.instance_of?(TrueClass) ? {} : super - { data: { bem: { name => attrs } } } + { 'data-bem': { name => js_attrs }.to_json } end def js=(new_js, save = true) save ? @js = new_js : new_js end