Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created September 30, 2015 02:14
Show Gist options
  • Save ruckus/5a976cf0d5a1bd3e711a to your computer and use it in GitHub Desktop.
Save ruckus/5a976cf0d5a1bd3e711a to your computer and use it in GitHub Desktop.
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