Hello.
Thank you for the work you have done on this gem, it is helping me!
Today I was having trouble trying to generate the leaflet_markers of the map through a Liquid forloop on Jekyll. The problem is that all the markers generated had the information of the first created on the forloop.
You can reproduce the problem with:
{% capture reproduce %}
{% for i in (1..5) %}
{% leaflet_marker
{
"latitude": {{ forloop.index }},
"longitude": {{ forloop.index }}.
}
%}
{% endfor %}
{% endcapture %}
{% for lm in reproduce %}
{{ lm }}
{% endfor %}
Expected result:
{id: "f82d0ff366578fb23102b3be3e4d350c", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } },
{id: "24a36c6449a3451d6a6d9f0a6d165f26", type: "LeafletMarker", value: { "latitude": 2, "longitude": 2. } },
{id: "3a4b4e4d949d12d278aa0c9b60e74ea0", type: "LeafletMarker", value: { "latitude": 3, "longitude": 3. } },
{id: "f49da7d4a91fb17300807cd026962774", type: "LeafletMarker", value: { "latitude": 4, "longitude": 4. } },
{id: "44b14612a326454314893f0962ffc1d2", type: "LeafletMarker", value: { "latitude": 5, "longitude": 5. } }
Actual ressult
{id: "f82d0ff366578fb23102b3be3e4d350c", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } },
{id: "24a36c6449a3451d6a6d9f0a6d165f26", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } },
{id: "3a4b4e4d949d12d278aa0c9b60e74ea0", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } },
{id: "f49da7d4a91fb17300807cd026962774", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } },
{id: "44b14612a326454314893f0962ffc1d2", type: "LeafletMarker", value: { "latitude": 1, "longitude": 1. } }
Why this happen?
As far as I could see (here and here) initialize method will be only called once on a for loop, so, using an **@**instance variable on the render will make first element being rendered each time.
How to fix
The only thing we have to do to fix that is changing (on leaflet-marker.rb) the lines
@input = parse_liquid_output_in(@input, context)
'{id: "' + SecureRandom.hex + '",
type: "LeafletMarker",
value: ' + @input + '},'
to
value = parse_liquid_output_in(@input, context)
'{id: "' + SecureRandom.hex + '",
type: "LeafletMarker",
value: ' + value + '},'
(As it is being done on leaflet-geojson.rb)
Fixed on a forked repo and worked perfectly. I would be great if this fix can be included as soon as possible so we don't have to use a forked gem.
Thank you again for the work you have done.
Greetings.