regenerate 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,11 @@
2
2
 
3
3
  require 'regenerate'
4
4
 
5
+ STDOUT.sync = true
6
+ STDERR.sync = true
7
+
5
8
  if ARGV.length == 1
6
- Regenerate.regenerate(ARGV[0])
9
+ Regenerate.regeneratePath(ARGV[0])
7
10
  else
8
11
  raise Exception, "regenerate expects exactly one argument: #{ARGV.inspect}"
9
12
  end
@@ -3,12 +3,3 @@
3
3
 
4
4
  require 'regenerate/web-page.rb'
5
5
  require 'regenerate/site-regenerator.rb'
6
-
7
- STDOUT.sync = true
8
- STDERR.sync = true
9
-
10
- #puts "ARGV = #{ARGV.inspect}"
11
-
12
- if ARGV.length >= 1
13
- Regenerate.regeneratePath(ARGV[0])
14
- end
@@ -7,11 +7,11 @@ module Regenerate
7
7
  def makeBackupFile(outFile)
8
8
  backupFileName = outFile+"~"
9
9
  if File.exists? backupFileName
10
- puts "Deleting existing backup file #{backupFileName} ..."
10
+ #puts " deleting existing backup file #{backupFileName} ..."
11
11
  File.delete (backupFileName)
12
12
  end
13
13
  if File.exists? outFile
14
- puts "Renaming file #{outFile} to #{backupFileName} ..."
14
+ #puts " renaming file #{outFile} to #{backupFileName} ..."
15
15
  File.rename(outFile, backupFileName)
16
16
  end
17
17
  backupFileName
@@ -48,7 +48,7 @@ module Regenerate
48
48
  :output => File.join(@baseDir, @outputSubDir)}
49
49
  @oppositeSourceType = {:source => :output, :output => :source}
50
50
  @checkNoChanges = false
51
- puts "SiteRegenerator, @baseDir = #{@baseDir.inspect}"
51
+ puts "SiteRegenerator initialized, @baseDir = #{@baseDir.inspect}"
52
52
  end
53
53
 
54
54
  # files & directories starting with "_" are not output files (they are other helper files)
@@ -72,13 +72,13 @@ module Regenerate
72
72
  # Generate an output file from a source file
73
73
  # (pathComponents represent the path from the root source directory to the actual file)
74
74
  def regenerateFileFromSource(srcFile, pathComponents)
75
- puts "regenerateFileFromSource, srcFile = #{srcFile}, pathComponents = #{pathComponents.inspect}"
75
+ #puts "regenerateFileFromSource, srcFile = #{srcFile}, pathComponents = #{pathComponents.inspect}"
76
76
  subPath = pathComponents.join("/")
77
77
  outFile = File.join(@sourceTypeDirs[:output], subPath)
78
- puts " outFile = #{outFile}"
78
+ #puts " outFile = #{outFile}"
79
79
  ensureDirectoryExists(File.dirname(outFile))
80
80
  extension = File.extname(srcFile).downcase
81
- puts " extension = #{extension}"
81
+ #puts " extension = #{extension}"
82
82
  if REGENERATE_EXTENSIONS.include? extension
83
83
  WebPage.new(srcFile).regenerateToOutputFile(outFile, checkNoChanges)
84
84
  else
@@ -88,13 +88,13 @@ module Regenerate
88
88
 
89
89
  # Generate a source file from an output file (if that can be done)
90
90
  def regenerateSourceFromOutput(outFile, pathComponents)
91
- puts "regenerateSourceFromOutput, outFile = #{outFile}, pathComponents = #{pathComponents.inspect}"
91
+ #puts "regenerateSourceFromOutput, outFile = #{outFile}, pathComponents = #{pathComponents.inspect}"
92
92
  subPath = pathComponents.join("/")
93
93
  srcFile = File.join(@sourceTypeDirs[:source], subPath)
94
- puts " srcFile = #{srcFile}"
94
+ #puts " srcFile = #{srcFile}"
95
95
  ensureDirectoryExists(File.dirname(srcFile))
96
96
  extension = File.extname(outFile).downcase
97
- puts " extension = #{extension}"
97
+ #puts " extension = #{extension}"
98
98
  if REGENERATE_EXTENSIONS.include? extension
99
99
  raise "Regeneration from output not yet implemented."
100
100
  else
@@ -104,9 +104,9 @@ module Regenerate
104
104
 
105
105
  # Regenerate (or generate) a file, either from source file or from output file
106
106
  def regenerateFile(srcFile, pathComponents, sourceType)
107
- puts "regenerateFile, srcFile = #{srcFile}, sourceType = #{sourceType.inspect}"
107
+ #puts "regenerateFile, srcFile = #{srcFile}, sourceType = #{sourceType.inspect}"
108
108
  outFile = File.join(@sourceTypeDirs[@oppositeSourceType[sourceType]], File.join(pathComponents))
109
- puts " outFile = #{outFile}"
109
+ #puts " outFile = #{outFile}"
110
110
  outFileDir = File.dirname(outFile)
111
111
  if !File.exists?(outFileDir)
112
112
  if sourceType == :output
@@ -124,9 +124,9 @@ module Regenerate
124
124
  # Regenerate (or generated) specified sub-directory or file in sub-directory
125
125
  # of source or output root directory (according to sourceType)
126
126
  def regenerateSubPath(pathComponents, sourceType)
127
- puts "regenerateSubPath, pathComponents = #{pathComponents.inspect}, sourceType = #{sourceType.inspect}"
127
+ #puts "regenerateSubPath, pathComponents = #{pathComponents.inspect}, sourceType = #{sourceType.inspect}"
128
128
  srcPath = File.join(@sourceTypeDirs[sourceType], File.join(pathComponents))
129
- puts " srcPath = #{srcPath}"
129
+ #puts " srcPath = #{srcPath}"
130
130
  if File.directory? (srcPath)
131
131
  for entry in Dir.entries(srcPath) do
132
132
  if ![".", ".."].include? entry
@@ -144,9 +144,9 @@ module Regenerate
144
144
  # the source or output root directory).
145
145
  def regeneratePath(path)
146
146
  path = File.expand_path(path)
147
- puts "SiteRegenerator.regeneratePath, path = #{path}"
147
+ #puts "SiteRegenerator.regeneratePath, path = #{path}"
148
148
  relativePath = Pathname.new(path).relative_path_from(Pathname.new(@baseDir))
149
- puts " relativePath = #{relativePath}"
149
+ #puts " relativePath = #{relativePath}"
150
150
  relativePathComponents = relativePath.to_s.split("/")
151
151
  puts " relativePathComponents = #{relativePathComponents.inspect}"
152
152
  subDir = relativePathComponents[0]
@@ -165,10 +165,12 @@ module Regenerate
165
165
 
166
166
  # Searching upwards from the current directory, find a file ".regenerate.rb" in the root directory of the project
167
167
  def self.findRegenerateScript(path, fileName)
168
+ puts "Find regenerate script ..."
168
169
  for dir in PathAndParents.new(path) do
169
170
  scriptFileName = File.join(dir, fileName)
170
171
  puts " looking for #{scriptFileName} ..."
171
172
  if File.exists?(scriptFileName)
173
+ puts " FOUND #{scriptFileName}"
172
174
  return scriptFileName
173
175
  end
174
176
  end
@@ -368,7 +368,7 @@ module Regenerate
368
368
 
369
369
  # Set the value of an instance variable of the page object
370
370
  def setPageObjectInstanceVar(varName, value)
371
- puts " setPageObjectInstanceVar, #{varName} = #{value.inspect}"
371
+ #puts " setPageObjectInstanceVar, #{varName} = #{value.inspect}"
372
372
  @pageObject.instance_variable_set(varName, value)
373
373
  end
374
374
 
@@ -508,13 +508,12 @@ module Regenerate
508
508
  # there are no differences between the new output and the existing output.
509
509
  def writeRegeneratedFile(outFile, checkNoChanges)
510
510
  backupFileName = makeBackupFile(outFile)
511
- puts "Outputting regenerated page to #{outFile} ..."
512
511
  File.open(outFile, "w") do |f|
513
512
  for component in @components do
514
513
  f.write(component.output)
515
514
  end
516
515
  end
517
- puts "Finished writing #{outFile}"
516
+ puts " wrote regenerated page to #{outFile}"
518
517
  if checkNoChanges
519
518
  checkAndEnsureOutputFileUnchanged(outFile, backupFileName)
520
519
  end
@@ -522,7 +521,7 @@ module Regenerate
522
521
 
523
522
  # Read in and parse lines from source file
524
523
  def readFileLines
525
- puts "Opening #{@fileName} ..."
524
+ puts "Reading source file #{@fileName} ..."
526
525
  lineNumber = 0
527
526
  File.open(@fileName).each_line do |line|
528
527
  line.chomp!
@@ -563,12 +562,12 @@ module Regenerate
563
562
  # Execute the Ruby components which consist of Ruby code to be evaluated in the context of the page object
564
563
  def executeRubyComponents
565
564
  fileDir = File.dirname(@fileName)
566
- puts "Executing ruby components in directory #{fileDir} ..."
565
+ #puts "Executing ruby components in directory #{fileDir} ..."
567
566
  Dir.chdir(fileDir) do
568
567
  for rubyComponent in @rubyComponents
569
568
  rubyCode = rubyComponent.text
570
- puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
571
- puts "Executing ruby (line #{rubyComponent.lineNumber}) #{rubyCode.inspect} ..."
569
+ #puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
570
+ #puts "Executing ruby (line #{rubyComponent.lineNumber}) #{rubyCode.inspect} ..."
572
571
  @pageObject.instance_eval(rubyCode, @fileName, rubyComponent.lineNumber)
573
572
  #puts "Finished executing ruby at line #{rubyComponent.lineNumber}"
574
573
  end
@@ -635,7 +634,7 @@ module Regenerate
635
634
  properties[property] = value
636
635
  end
637
636
  propertiesFileName = relative_path(self.class.propertiesFileName(@baseFileName))
638
- puts "Saving properties #{properties.inspect} to #{propertiesFileName}"
637
+ #puts "Saving properties #{properties.inspect} to #{propertiesFileName}"
639
638
  ensureDirectoryExists(File.dirname(propertiesFileName))
640
639
  File.open(propertiesFileName,"w") do |f|
641
640
  f.write(JSON.pretty_generate(properties))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regenerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: