Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions lib/x-editable-rails/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def editable(object, method, options = {})
nid = options.delete(:nid)
nested = options.delete(:nested)
title = options.delete(:title) do
klass = nested ? object.class.const_get(nested.to_s.classify) : object.class
klass = nested ? object.class.const_get(nested.to_s.singularize.capitalize) : object.class
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [104/80]

klass.human_attribute_name(method)
end

Expand Down Expand Up @@ -72,13 +72,7 @@ def editable(object, method, options = {})
})

content_tag tag, html_options do
if %w(select checklist).include?(data[:type].to_s) && !source.is_a?(String)
source = normalize_source(source)
content = source.detect { |t| output_value == output_value_for(t[0]) }
content.present? ? content[1] : ""
else
safe_join(source_values_for(value, source), tag(:br))
end
safe_join(source_values_for(value, source), tag(:br)) unless %w(select checklist).include? data[:type]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [116/80]

end
else
error || safe_join(source_values_for(value, source), tag(:br))
Expand All @@ -87,17 +81,6 @@ def editable(object, method, options = {})

private

def normalize_source(source)
return [] unless source
source.map do |el|
if el.is_a? Array
el
else
[el[:value], el[:text]]
end
end
end

def output_value_for(value)
value = case value
when TrueClass
Expand Down Expand Up @@ -152,9 +135,11 @@ def format_source(source, value)
if source.is_a?(Array) && source.first.is_a?(String) && source.size == 2
{ '1' => source[0], '0' => source[1] }
end
else
when String
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent when as deep as case.

if source.is_a?(Array) && source.first.is_a?(String)
source.map { |v| { value: v, text: v } }
source.inject({}){|hash, key| hash.merge(key => key)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space missing to the left of {.
Space between { and | missing.
Space missing inside }.

elsif source.is_a?(Hash)
source
end
end

Expand Down