Method: Docgen::CLI.read_sql_file

Defined in:
lib/docgen/cli.rb

.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.expand_path(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