Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-generate ButterKnife @Bind calls
require 'rubygems'
require 'nokogiri'
xml = Nokogiri::XML(File.read(ARGV[0]))
xml.remove_namespaces!
class String
def camel_case
return self if self !~ /_/ && self =~ /[A-Z]+.*/
split('_').map{|e| e.capitalize}.join
end
end
id_attrs = xml.xpath("//@id")
id_attrs.each do |attr|
name = attr.value.gsub("@+id/", "")
parentObjectName = attr.parent.name
propertyName = name.camel_case
puts "@Bind(R.id.#{name})\n#{parentObjectName} m#{propertyName};"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.