Created
September 30, 2015 02:14
-
-
Save ruckus/5a976cf0d5a1bd3e711a to your computer and use it in GitHub Desktop.
Auto-generate ButterKnife @Bind calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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