github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazyview/html/generate_attr (about) 1 #!/usr/bin/env ruby 2 3 require 'active_support' 4 include ActiveSupport::Inflector 5 6 attributes = File.read("attributes").split 7 tags = File.read("tags").split 8 9 f = File.open("autoattributes.go", "w") 10 11 f << "package html\n\n" 12 13 f << "import \"github.com/golazy/golazy/lazyview/nodes\"\n\n" 14 15 attributes.each do |attr| 16 fn = camelize(attr.gsub("-","_")) 17 fn += "Attr" if tags.include?(attr) 18 fn = "DataAttrValue" if attr == "data" 19 20 f << "// #{fn} sets #{attr} attribute\n" 21 f << "func #{fn}(value ...string) nodes.Attr {\n" 22 f << " return nodes.NewAttr(\"#{attr}\", value...)\n" 23 f << "}\n\n" 24 end 25 26 f.close