sprout 0.7.198 → 0.7.201

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

@@ -76,6 +76,10 @@ module Sprout #:nodoc:
76
76
  @w.puts(msg)
77
77
  end
78
78
 
79
+ def close_write
80
+ @w.close_write
81
+ end
82
+
79
83
  def read
80
84
  return @r.read
81
85
  end
@@ -98,6 +98,10 @@ module Sprout
98
98
  attr_accessor :organization
99
99
  # The production file that this Project will generate
100
100
  attr_accessor :output
101
+ # Terminal command to preprocessor application that accepts STDIN and returns on STDOUT
102
+ attr_accessor :preprocessor
103
+ # Folder where preprocessed files will be created. Defaults to '.preprocessed'
104
+ attr_accessor :preprocessed_path
101
105
  # The real name of the project, usually capitalized like a class name 'SomeProject'
102
106
  attr_accessor :project_name
103
107
  # The folder where compile time skins can be loaded from
@@ -30,17 +30,13 @@ module Sprout
30
30
  #
31
31
  class ToolTask < Rake::FileTask
32
32
 
33
- # Arguments to be prepended in front of the command line output
34
- attr_accessor :prepended_args
35
- # Arguments to appended at the end of the command line output
36
- attr_accessor :appended_args
37
-
38
33
  def initialize(name, app) # :nodoc:
39
34
  super
40
- @prepended_args = nil
41
- @appended_args = nil
42
- @default_gem_name = nil
43
- @default_gem_path = nil
35
+ @preprocessed_path = nil
36
+ @prepended_args = nil
37
+ @appended_args = nil
38
+ @default_gem_name = nil
39
+ @default_gem_path = nil
44
40
  initialize_task
45
41
  end
46
42
 
@@ -115,8 +111,80 @@ module Sprout
115
111
 
116
112
  return result
117
113
  end
114
+
115
+ # Arguments to be prepended in front of the command line output
116
+ def prepended_args=(args)
117
+ @prepended_args = args
118
+ end
119
+
120
+ # Returns arguments that were prepended in front of the command line output
121
+ def prepended_args
122
+ @prepended_args
123
+ end
124
+
125
+ # Arguments to appended at the end of the command line output
126
+ def appended_args=(args)
127
+ @appended_args = args
128
+ end
129
+
130
+ # Returns arguments that were appended at the end of the command line output
131
+ def appended_args
132
+ @appended_args
133
+ end
134
+
135
+ # Command line arguments to execute preprocessor.
136
+ # The preprocessor execution should accept text via STDIN and return its processed content via STDOUT.
137
+ #
138
+ # In the following example, the +MXMLCTask+ has been configured to use the C preprocessor (cpp) and
139
+ # place the processed output into a +_preprocessed+ folder, instead of the hidden default folder at
140
+ # .preprocessed.
141
+ #
142
+ # One side effect of the cpp tool is that it adds 2 carriage returns to the top of any processed files,
143
+ # so we have simply piped its output to the tail command which then strips those carriage returns from
144
+ # all files - which retains accurate line numbers for any compiler error messages.
145
+ #
146
+ # mxmlc 'bin/SomeProject.swf' => :corelib do |t|
147
+ # t.input = 'src/SomeProject.as'
148
+ # t.default_size = '800 600'
149
+ # t.preprocessor = 'cpp -D__DEBUG=true -P - - | tail -c +3'
150
+ # t.preprocessed_path = '_preprocessed'
151
+ # end
152
+ #
153
+ # Any source files found in this example project can now take advantage of any tools, macros or syntax
154
+ # available to CPP. For example, the +__DEBUG+ variable is now defined and can be accessed in ActionScript
155
+ # source code as follows:
156
+ #
157
+ # public static const DEBUG:Boolean = __DEBUG;
158
+ #
159
+ # Any commandline tool identified on this attribute will be provided the content of each file on STDIN and
160
+ # whatever it returns to STDOUT will be written into the +preprocessed_path+. This means that we can
161
+ # take advantage of the entire posix tool chain by piping inputs and outputs from one tool to another.
162
+ # Whatever the last tool returns will be handed off to the concrete compiler.
163
+ def preprocessor=(preprocessor)
164
+ @preprocessor = preprocessor
165
+ end
166
+
167
+ def preprocessor
168
+ @preprocessor
169
+ end
170
+
171
+ # Path where preprocessed files are stored. Defaults to '.preprocessed'
172
+ def preprocessed_path=(preprocessed_path)
173
+ @preprocessed_path = preprocessed_path
174
+ end
175
+
176
+ def preprocessed_path
177
+ @preprocessed_path ||= '.preprocessed'
178
+ end
179
+
180
+ def display_preprocess_message # :nodoc:
181
+ if(!preprocessor.nil?)
182
+ puts ">> Preprocessed text files in: #{File.join(Dir.pwd, preprocessed_path)} with #{preprocessor}"
183
+ end
184
+ end
118
185
 
119
186
  def execute(*args)
187
+ display_preprocess_message
120
188
  #puts ">> Executing #{File.basename(exe)} #{to_shell}"
121
189
  exe = Sprout.get_executable(gem_name, gem_path, gem_version)
122
190
  User.execute(exe, to_shell)
@@ -319,15 +387,16 @@ module Sprout
319
387
  # rake tasks for Command Line Interface (CLI) compilers.
320
388
  #
321
389
  class TaskParam
322
- attr_accessor :name
323
- attr_accessor :type
324
- attr_accessor :validator
390
+ attr_accessor :belongs_to
325
391
  attr_accessor :description
326
- attr_accessor :visible
327
392
  attr_accessor :hidden_name
328
393
  attr_accessor :hidden_value
394
+ attr_accessor :name
395
+ attr_accessor :preprocessable
329
396
  attr_accessor :required
330
- attr_accessor :belongs_to
397
+ attr_accessor :type
398
+ attr_accessor :validator
399
+ attr_accessor :visible
331
400
 
332
401
  attr_writer :prefix
333
402
  attr_writer :value
@@ -433,6 +502,94 @@ module Sprout
433
502
  result << "def #{name}=(#{type})\n @#{name} = #{type}\nend\n\n"
434
503
  return result
435
504
  end
505
+
506
+ protected
507
+
508
+ def should_preprocess?
509
+ return preprocessable && !belongs_to.preprocessor.nil?
510
+ end
511
+
512
+ def prepare_preprocessor_paths(paths)
513
+ processed = []
514
+ paths.each do |path|
515
+ processed << prepare_preprocessor_path(path)
516
+ end
517
+ return processed
518
+ end
519
+
520
+ def prepare_preprocessor_files(files)
521
+ processed = []
522
+ files.each do |file|
523
+ processed << prepare_preprocessor_file(file)
524
+ end
525
+ return processed
526
+ end
527
+
528
+ def cleaned_preprocessed_path(path)
529
+ File.join(belongs_to.preprocessed_path, path.gsub('../', 'backslash/'))
530
+ end
531
+
532
+ def prepare_preprocessor_path(path)
533
+ processed_path = cleaned_preprocessed_path(path)
534
+ FileUtils.mkdir_p(processed_path)
535
+ files = FileList[path + file_expression]
536
+ files.each do |input_file|
537
+ prepare_preprocessor_file(input_file)
538
+ end
539
+
540
+ return processed_path
541
+ end
542
+
543
+ def prepare_preprocessor_file(input_file)
544
+ output_file = cleaned_preprocessed_path(input_file)
545
+ setup_preprocessing_file_tasks(input_file, output_file)
546
+ return output_file
547
+ end
548
+
549
+ def text_file?(file_name)
550
+ [/\.as$/, /\.txt$/, /\.mxml$/, /\.xml$/, /\.js$/, /\.html$/, /\.htm$/].select { |regex|
551
+ if(file_name.match(regex))
552
+ return true
553
+ end
554
+ }.size > 0
555
+ end
556
+
557
+ def setup_preprocessing_file_tasks(input_file, output_file)
558
+ return if(File.directory?(input_file))
559
+ CLEAN.add(belongs_to.preprocessed_path) if(!CLEAN.index(belongs_to.preprocessed_path))
560
+
561
+ file input_file
562
+ file output_file => input_file do
563
+ dir = File.dirname(output_file)
564
+ if(!File.exists?(dir))
565
+ FileUtils.mkdir_p(dir)
566
+ end
567
+ File.open(input_file, 'r') do |readable|
568
+ File.open(output_file, 'w+') do |writable|
569
+ if(text_file?(input_file))
570
+ preprocess_content(readable, writable, belongs_to.preprocessor, input_file)
571
+ else
572
+ writable.write(readable.read)
573
+ end
574
+ end
575
+ end
576
+ end
577
+ belongs_to.prerequisites << output_file
578
+ end
579
+
580
+ def preprocess_content(readable, writable, processor, file)
581
+ process = ProcessRunner.new(processor)
582
+ process.puts(readable.read)
583
+ process.close_write
584
+ result = process.read
585
+ error = process.read_err
586
+ if(error.size > 0)
587
+ belongs_to.display_preprocess_message
588
+ FileUtils.rm_rf(belongs_to.preprocessed_path)
589
+ raise ExecutionError.new("[ERROR] Preprocessor failed on file #{file} #{error}")
590
+ end
591
+ writable.write(result)
592
+ end
436
593
 
437
594
  end
438
595
 
@@ -456,16 +613,32 @@ module Sprout
456
613
 
457
614
  # Concrete param object for :file values
458
615
  class FileParam < TaskParam # :nodoc:
616
+
459
617
  def prepare_prerequisites
460
618
  if(value && value != belongs_to.name.to_s)
461
- file value
462
- belongs_to.prerequisites << value
619
+ if(should_preprocess?)
620
+ @value = prepare_preprocessor_file(value)
621
+ else
622
+ file value
623
+ belongs_to.prerequisites << value
624
+ end
463
625
  end
464
626
  end
465
627
  end
466
628
 
467
629
  # Concrete param object for :path values
468
- class PathParam < FileParam # :nodoc:
630
+ class PathParam < TaskParam # :nodoc:
631
+
632
+ def prepare_prerequisites
633
+ if(value && value != belongs_to.name.to_s)
634
+ if should_preprocess?
635
+ @value = prepare_preprocessor_path(value)
636
+ else
637
+ file value
638
+ belongs_to.prerequisites << value
639
+ end
640
+ end
641
+ end
469
642
  end
470
643
 
471
644
  # Concrete param object for :boolean values
@@ -540,26 +713,36 @@ module Sprout
540
713
  end
541
714
 
542
715
  def prepare_prerequisites
543
- value.each do |f|
544
- file f
545
- belongs_to.prerequisites << f
716
+ if should_preprocess?
717
+ @value = prepare_preprocessor_files(value)
718
+ else
719
+ value.each do |f|
720
+ file f
721
+ belongs_to.prerequisites << f
722
+ end
546
723
  end
547
724
  end
725
+
548
726
  end
549
727
 
550
728
  # Concrete param object for collections of paths
551
729
  class PathsParam < FilesParam # :nodoc:
552
730
 
553
731
  def prepare_prerequisites
554
- usr = User.new
555
- value.each do |f|
556
- files = FileList[f + file_expression]
557
- files.each do |req_file|
558
- file req_file
559
- belongs_to.prerequisites << req_file
732
+ if should_preprocess?
733
+ @value = prepare_preprocessor_paths(value)
734
+ else
735
+ value.each do |path|
736
+ files = FileList[path + file_expression]
737
+ files.each do |f|
738
+ file f
739
+ belongs_to.prerequisites << f
740
+ end
560
741
  end
561
742
  end
562
743
  end
744
+
745
+
563
746
  end
564
747
 
565
748
  # Concrete param object for collections of files
@@ -2,7 +2,7 @@ module Sprout
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 7
5
- TINY = 198
5
+ TINY = 201
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  MAJOR_MINOR = [MAJOR, MINOR].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.198
4
+ version: 0.7.201
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Bayes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-09 00:00:00 -08:00
12
+ date: 2009-01-13 00:00:00 -08:00
13
13
  default_executable: sprout
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency