class ERBLint::Utils::RubyToERB
Public Class Methods
escape_quote(str)
click to toggle source
# File lib/erb_lint/utils/ruby_to_erb.rb, line 45 def escape_quote(str) str.gsub('"', """) end
html_options_to_tag_attributes(hash_node)
click to toggle source
# File lib/erb_lint/utils/ruby_to_erb.rb, line 9 def html_options_to_tag_attributes(hash_node) hash_node.children.map do |pair_node| key_node, value_node = *pair_node key = ruby_to_erb(key_node, "=") { |s| s.tr("_", "-") } value = ruby_to_erb(value_node, "=") { |s| escape_quote(s) } [key, "\"#{value}\""].join("=") end.join(" ") end
ruby_to_erb(node, indicator = nil) { |s| ... }
click to toggle source
# File lib/erb_lint/utils/ruby_to_erb.rb, line 18 def ruby_to_erb(node, indicator = nil, &block) return node if node.nil? || node.is_a?(String) case node.type when :str, :sym s = node.children.first.to_s s = yield s if block_given? s when :true, :false node.type.to_s when :nil "" when :dstr node.children.map do |child| case child.type when :str ruby_to_erb(child, indicator, &block) when :begin ruby_to_erb(child.children.first, indicator, &block) else raise Error, "unexpected #{child.type} in :dstr node" end end.join else "<%#{indicator} #{node.loc.expression.source} %>" end end