lib/adiwg/mdtranslator/writers/mdWriters.rb in adiwg-mdtranslator-1.2.1 vs lib/adiwg/mdtranslator/writers/mdWriters.rb in adiwg-mdtranslator-1.3.0
- old
+ new
@@ -2,58 +2,55 @@
# History:
# Stan Smith 2014-12-11 original script
# Stan Smith 2012-12-16 generalized handleWriter to use :writerName
# Stan Smith 2015-03-04 changed method of setting $WriterNS
+# Stan Smith 2015-06-22 replace global ($response) with passed in object (responseObj)
+# Stan Smith 2015-07-14 refactored to make iso19110 independent of iso19115_2 classes
+# Stan Smith 2015-07-14 refactored to eliminate namespace globals $WriterNS and $IsoNS
module ADIWG
module Mdtranslator
module Writers
- def self.handleWriter(intObj)
+ def self.handleWriter(intObj, responseObj, paramsObj)
- # this is a temp fix until the directory structure is changed
- if $response[:writerName] == 'iso'
- $response[:writerPass] = false
- $response[:writerMessages] << 'Writer not called - see following message(s):\n'
- $response[:writerMessages] << "Writer name 'iso' is not supported."
- return false
- end
-
- # use writer name to load and initiate requested writer
- # build directory path for writer from writerName
- writerDir = File.join(path_to_resources, $response[:writerName])
+ # use writerName from responseObj to build directory path to writer
+ # the writer's high level folder must be under the 'writers' directory
+ writerDir = File.join(path_to_writers, responseObj[:writerName])
if File.directory?(writerDir)
- # if directory path exists, build writer file name and then require it
- writerFile = File.join(writerDir, $response[:writerName] + '_writer')
+ # if directory path exists, build writer file name and require it
+ writerFile = File.join(writerDir, responseObj[:writerName] + '_writer')
require writerFile
- writerClassName = $response[:writerName].dup
- writerClassName[0] = writerClassName[0].upcase
- $WriterNS = ADIWG::Mdtranslator::Writers.const_get(writerClassName)
- # pass internal object to requested writer
- $response[:writerOutput] = $WriterNS.startWriter(intObj)
+ # build the namespace for the writer
+ writerNS = responseObj[:writerName].dup
+ writerNS[0] = writerNS[0].upcase
+ # pass internal object and response object to the writer
+ responseObj[:writerOutput] = ADIWG::Mdtranslator::Writers.const_get(writerNS).startWriter(intObj, responseObj, paramsObj)
+
else
# directory path was not found
- $response[:writerPass] = false
- $response[:writerMessages] << 'Writer not called - see following message(s):\n'
- $response[:writerMessages] << "Writer name '#{$response[:writerName]}' is not supported."
+ responseObj[:writerPass] = false
+ responseObj[:writerMessages] << 'Writer not called - see following message(s):\n'
+ responseObj[:writerMessages] << "Writer name '#{responseObj[:writerName]}' is not supported."
return false
end
end
# return path to writers
- def self.path_to_resources
+ def self.path_to_writers
File.dirname(File.expand_path(__FILE__))
end
# return writer readme text
+ # this is called from the Rails API
def self.get_writer_readme(writer)
readmeText = 'No readme found'
- path = File.join(path_to_resources, writer, 'readme.md')
+ path = File.join(path_to_writers, writer, 'readme.md')
if File.exist?(path)
file = File.open(path, 'r')
readmeText = file.read
file.close
end