replacing event listener by ActiveSupport::Notifications instead (WIP)
did
committed May 16, 2015
commit afc1f83be8058b7909251a066605fac7b48d17fa
Showing 5
changed files with
21 additions
and 14 deletions
locomotive/steam/liquid/tags/editable/base.rb b/lib/locomotive/steam/liquid/tags/editable/base.rb
+4
-5
| @@ | @@ -22,10 +22,8 @@ module Locomotive |
| end | |
| def parse(tokens) | |
| - | super |
| - | |
| - | if listener = options[:events_listener] |
| - | listener.emit(@tag_name.to_sym, page: options[:page], attributes: default_element_attributes) |
| + | super.tap do |
| + | ActiveSupport::Notifications.instrument("steam.parse.editable.#{@tag_name}", page: options[:page], attributes: default_element_attributes) |
| end | |
| end | |
| @@ | @@ -53,7 +51,8 @@ module Locomotive |
| fixed: !!@element_options[:fixed], | |
| disabled: false, | |
| inline_editing: true, | |
| - | from_parent: false |
| + | from_parent: false, |
| + | type: @tag_name.to_sym |
| } | |
| end | |
spec/support/liquid.rb
+5
-0
| @@ | @@ -10,6 +10,11 @@ end |
| module Liquid | |
| class SimpleEventsListener | |
| + | def initialize |
| + | ActiveSupport::Notifications.subscribe(/^steam\.parse\.editable/) do |name, start, finish, id, payload| |
| + | emit(name, payload) |
| + | end |
| + | end |
| def emit(name, options = {}) | |
| (@stack ||= []) << [name, options] | |
| end | |
spec/unit/liquid/tags/editable/control_spec.rb
+4
-3
| @@ | @@ -3,8 +3,8 @@ require 'spec_helper' |
| describe Locomotive::Steam::Liquid::Tags::Editable::Control do | |
| let(:page) { instance_double('Page') } | |
| - | let(:listener) { Liquid::SimpleEventsListener.new } |
| - | let(:options) { { events_listener: listener, page: page } } |
| + | let!(:listener) { Liquid::SimpleEventsListener.new } |
| + | let(:options) { { page: page } } |
| let(:source) { "{% editable_control menu, hint: 'some text', options: 'true=Yes,false=No' %}false{% endeditable_control %}" } | |
| @@ | @@ -47,7 +47,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Control do |
| subject { listener.events.first.first } | |
| it 'records the name of the event' do | |
| - | is_expected.to eq :editable_control |
| + | is_expected.to eq "steam.parse.editable.editable_control" |
| end | |
| describe 'attributes' do | |
| @@ | @@ -55,6 +55,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Control do |
| subject { listener.events.first.last[:attributes] } | |
| it { is_expected.to include(block: nil) } | |
| + | it { is_expected.to include(type: :editable_control) } |
| it { is_expected.to include(slug: 'menu') } | |
| it { is_expected.to include(options: 'true=Yes,false=No') } | |
| it { is_expected.to include(hint: 'some text') } | |
spec/unit/liquid/tags/editable/file_spec.rb
+4
-3
| @@ | @@ -3,8 +3,8 @@ require 'spec_helper' |
| describe Locomotive::Steam::Liquid::Tags::Editable::File do | |
| let(:page) { instance_double('Page', updated_at: DateTime.parse('2007-06-29 21:00:00')) } | |
| - | let(:listener) { Liquid::SimpleEventsListener.new } |
| - | let(:options) { { events_listener: listener, page: page } } |
| + | let!(:listener) { Liquid::SimpleEventsListener.new } |
| + | let(:options) { { page: page } } |
| let(:source) { "{% editable_file banner, hint: 'some text' %}http://www.placehold.it/500x500{% endeditable_file %}" } | |
| @@ | @@ -47,7 +47,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do |
| subject { listener.events.first.first } | |
| it 'records the name of the event' do | |
| - | is_expected.to eq :editable_file |
| + | is_expected.to eq 'steam.parse.editable.editable_file' |
| end | |
| describe 'attributes' do | |
| @@ | @@ -55,6 +55,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::File do |
| subject { listener.events.first.last[:attributes] } | |
| it { is_expected.to include(block: nil) } | |
| + | it { is_expected.to include(type: :editable_file) } |
| it { is_expected.to include(slug: 'banner') } | |
| it { is_expected.to include(hint: 'some text') } | |
| it { is_expected.to include(default_source_url: 'http://www.placehold.it/500x500') } | |
spec/unit/liquid/tags/editable/text_spec.rb
+4
-3
| @@ | @@ -3,8 +3,8 @@ require 'spec_helper' |
| describe Locomotive::Steam::Liquid::Tags::Editable::Text do | |
| let(:page) { instance_double('Page') } | |
| - | let(:listener) { Liquid::SimpleEventsListener.new } |
| - | let(:options) { { events_listener: listener, page: page } } |
| + | let!(:listener) { Liquid::SimpleEventsListener.new } |
| + | let(:options) { { page: page } } |
| let(:source) { "{% editable_text title, hint: 'Simple short text' %}Hello world{% endeditable_text %}" } | |
| @@ | @@ -47,7 +47,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do |
| subject { listener.events.first.first } | |
| it 'records the name of the event' do | |
| - | is_expected.to eq :editable_text |
| + | is_expected.to eq 'steam.parse.editable.editable_text' |
| end | |
| describe 'attributes' do | |
| @@ | @@ -55,6 +55,7 @@ describe Locomotive::Steam::Liquid::Tags::Editable::Text do |
| subject { listener.events.first.last[:attributes] } | |
| it { is_expected.to include(block: nil) } | |
| + | it { is_expected.to include(type: :editable_text) } |
| it { is_expected.to include(slug: 'title') } | |
| it { is_expected.to include(hint: 'Simple short text') } | |
| it { is_expected.to include(format: 'html') } | |