Merge pull request #108 from corgibytes/variables-as-values
Enabled the use of variable values as the default values for editable con
This commit is contained in:
commit
bf4b2be2b9
@ -125,5 +125,17 @@ Scenario: Insert editable files
|
||||
"""
|
||||
My application file is /default.pdf
|
||||
"""
|
||||
|
||||
|
||||
Scenario: Render liquid variable used as default editable file name
|
||||
Given a page named "hello-world" with the template:
|
||||
"""
|
||||
{% assign default_file_name = '/different-default.pdf' %}
|
||||
My application file is {% editable_file 'a_file', hint: 'please enter a new file' %}{{ default_file_name }}{% endeditable_file %}
|
||||
"""
|
||||
When I view the rendered page at "/hello-world"
|
||||
Then the rendered output should look like:
|
||||
"""
|
||||
|
||||
My application file is /different-default.pdf
|
||||
"""
|
||||
|
||||
|
@ -27,7 +27,7 @@ module Locomotive
|
||||
:slug => @slug,
|
||||
:hint => @options[:hint],
|
||||
:default_attribute => @options[:default],
|
||||
:default_content => default_content,
|
||||
:default_content => default_content_option,
|
||||
:assignable => @options[:assignable],
|
||||
:disabled => false,
|
||||
:from_parent => false
|
||||
@ -41,6 +41,9 @@ module Locomotive
|
||||
element = current_page.find_editable_element(context['block'].try(:name), @slug)
|
||||
|
||||
if element.present?
|
||||
unless element.default_content.present?
|
||||
element.default_content = render_default_content(context)
|
||||
end
|
||||
render_element(context, element)
|
||||
else
|
||||
Locomotive.logger "[editable element] missing element `#{context['block'].try(:name)}` / #{@slug} on #{current_page.fullpath}"
|
||||
@ -58,15 +61,20 @@ module Locomotive
|
||||
raise 'FIXME: has to be overidden'
|
||||
end
|
||||
|
||||
|
||||
def default_content
|
||||
def default_content_option
|
||||
result = nil
|
||||
if @options[:default].present?
|
||||
@context[:page].send(@options[:default])
|
||||
else
|
||||
@nodelist.first.to_s
|
||||
result = @context[:page].send(@options[:default])
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def render_default_content(context)
|
||||
puts "Old: #{@nodelist.first.to_s}"
|
||||
result = render_all(@nodelist, context)
|
||||
puts "New: #{result.inspect}"
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user