Class: Docgen::CLI
Constant Summary
Constants included from LanguageParser
Class Method Summary collapse
-
.convert_comment(comment) ⇒ Object
convert_comment( comment ).
- .execute(stdout, arguments = []) ⇒ Object
-
.read_sql_file(file_name) ⇒ Object
read_sql_file( file_name ).
-
.run_template(template_name, bind) ⇒ Object
run_template( template_name, bind ).
Class Method Details
.convert_comment(comment) ⇒ Object
convert_comment( comment )
comment - An SQL Comment
This converts and SQL comment into a JavaDoc style comment
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/docgen/cli.rb', line 100 def self.convert_comment( comment ) # First clean off all of the '--' markers cleaned = "" comment.each_line { |line| line.sub!( /\s*\-\-\s*/, "" ) line.strip! cleaned += "#{line}\n" if ( line.length > 0 ) } # Now create a new buffer with the proper JavaDoc formatting # around it converted = "/**\n" cleaned.each_line { |line| converted += " * #{line}" } converted += " */\n" converted end |
.execute(stdout, arguments = []) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/docgen/cli.rb', line 207 def self.execute(stdout, arguments=[]) # NOTE: the option -p/--path= is given as an example, and should be replaced in your application. = { :path => '~' } = %w( ) parser = OptionParser.new do |opts| opts. = " Generate HTML Doc for SQL\n\n Usage: \#{File.basename($0)} [options]\n\n Options are:\n BANNER\n opts.separator \"\"\n opts.on(\"-s\", \"--source=Source\", String,\n \"The input SQL file.\") { |arg| options[:source] = arg }\n opts.on(\"-h\", \"--help\",\n \"Show this help message.\") { stdout.puts opts; exit }\n opts.parse!(arguments)\n\n if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }\n stdout.puts opts; exit\n end\n end\n\n source = options[:source]\n\n # do stuff\n if source\n read_sql_file( source )\n else\n print \"Must specify an input SQL file\\n\"\n end\nend\n".gsub(/^ /,'') |
.read_sql_file(file_name) ⇒ Object
read_sql_file( file_name )
file_name - The name of the file
This reads and parses the file.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/docgen/cli.rb', line 130 def self.read_sql_file( file_name ) # Read the file contents print "Parsing #{file_name}...\n" fh = File.open( file_name ) in_text = fh.read() fh.close() # Tokenize the Java tokenizer = SQLTokenizer.new( ) tokenizer.parse( in_text ) # Run it through the language parser languagescanner = SQLLanguageScanner.new() languagescanner.parse( tokenizer.tokens ) # Get the tables tables = languagescanner.tables @@output_dir = File.(File.dirname(file_name))+"/html_doc" FileUtils.rm_rf @@output_dir FileUtils.mkdir_p @@output_dir # Iterate over each table and make the HTML file for it tables.each { |table| # Tell the user what we are building print "Building #{table.name}.html\n" # Parse the JavaDoc in the comments attached to the table jd = ExtendedJavaDoc.new() jd.parse( convert_comment( table.comment ) ) # Fill the field comment value with the appropriate comment from the # JavaDoc table.fields.each { |field| field.comment = jd.fieldDescriptions[ field.name.to_s.downcase.strip ] } # Setup other locals that the template will use table_comment = jd.tableDescription relates_to = jd.relatesTo # Create the HTML file and use the template to build it fh = File.new("#{@@output_dir}/#{table.name}.html", "w" ) fh.print run_template( "table_page.html.template", binding ) fh.close() } # Build the table index print "Building tables.html\n" fh = File.new("#{@@output_dir}/tables.html", "w" ) fh.print run_template( "tables.html.template", binding ) fh.close() # Build the main index page print "Building index.html\n" fh = File.new("#{@@output_dir}/index.html", "w" ) fh.print run_template( "index.html.template", binding ) fh.close() end |
.run_template(template_name, bind) ⇒ Object
run_template( template_name, bind )
template_name - The name of the template file bind - The binding to pass to the template
This runs the specified template with the bindings and returns the text output.
87 88 89 90 91 92 |
# File 'lib/docgen/cli.rb', line 87 def self.run_template( template_name, bind ) erb = ERB.new( File.new( File.dirname(__FILE__)+"/../../templates/docgen/#{template_name}" ).read ) erb.result( bind ) end |