mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Make Event's location accessible from Liquid templates.
This commit is contained in:
parent
1406f37d48
commit
dd507e3cbf
4 changed files with 37 additions and 0 deletions
|
@ -117,4 +117,8 @@ class EventDrop
|
|||
@object.created_at
|
||||
}
|
||||
end
|
||||
|
||||
def _location_
|
||||
@object.location
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require 'liquid'
|
||||
|
||||
Location = Struct.new(:lat, :lng, :radius, :speed, :course)
|
||||
|
||||
class Location
|
||||
include LiquidDroppable
|
||||
|
||||
protected :[]=
|
||||
|
||||
def initialize(data = {})
|
||||
|
@ -86,3 +90,13 @@ class Location
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class LocationDrop
|
||||
KEYS = Location.members.map(&:to_s).concat(%w[latitude longitude])
|
||||
|
||||
def before_method(key)
|
||||
if KEYS.include?(key)
|
||||
@object.__send__(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,4 +53,16 @@ describe Location do
|
|||
expect(Location.new(lat: 2, radius: 1).present?).to be_falsy
|
||||
expect(Location.new(lng: 3, radius: 1).present?).to be_falsy
|
||||
end
|
||||
|
||||
it "is droppable" do
|
||||
{
|
||||
'{{location.lat}}' => '2.0',
|
||||
'{{location.latitude}}' => '2.0',
|
||||
'{{location.lng}}' => '3.0',
|
||||
'{{location.longitude}}' => '3.0',
|
||||
}.each { |template, result|
|
||||
expect(Liquid::Template.parse(template).render('location' => location.to_liquid)).to eq(result),
|
||||
"expected #{template.inspect} to expand to #{result.inspect}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -174,6 +174,8 @@ describe EventDrop do
|
|||
'title' => 'some title',
|
||||
'url' => 'http://some.site.example.org/',
|
||||
}
|
||||
@event.lat = 2
|
||||
@event.lng = 3
|
||||
@event.save!
|
||||
end
|
||||
|
||||
|
@ -210,4 +212,9 @@ describe EventDrop do
|
|||
t = '{{created_at | date:"%FT%T%z" }}'
|
||||
interpolate(t, @event).should eq(@event.created_at.strftime("%FT%T%z"))
|
||||
end
|
||||
|
||||
it 'should have _location_' do
|
||||
t = '{{_location_.lat}},{{_location_.lng}}'
|
||||
interpolate(t, @event).should eq("2.0,3.0")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue