root/trunk/lib/picolena/picolena_generator.rb

Revision 335, 11.1 kB (checked in by eric.dumin..@gmail.com, 7 months ago)

Creating environment.rb as template

Line 
1 require 'tempfile'
2 require 'fileutils'
3 require 'pathname'
4
5 class PicolenaGenerator < RubiGen::Base #:nodoc:
6
7   DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
8                               Config::CONFIG['ruby_install_name'])
9
10   default_options :destination => 'picolena'
11
12   attr_reader :name
13
14   def initialize(runtime_args, runtime_options = {})
15     super
16     usage if args.empty? and !options[:spec_only]
17     @destination_root = options[:destination]
18
19     @directories_to_index=if options[:spec_only] then
20        "/whatever : /whatever"
21     else
22       ARGV.collect{|relative_path|
23         abs_dir=Pathname.new(relative_path).realpath.to_s
24         "\"#{abs_dir}\" : \"#{abs_dir}\""
25       }.join("\n  ")     
26     end
27
28     extract_options
29   end
30
31   def manifest
32     script_options     = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
33
34     record do |m|
35       #Create base dir
36       m.directory ''
37
38       # Picolena file structure, without any plugin.
39       BASEDIRS.each { |path|
40         # Ensure appropriate folder exists
41         m.directory path
42         # Copy every file included in BASEDIRS
43         m.folder path, path
44       }
45
46       # Moved plugins away so they don't get parsed by rdoc/ri.
47       RAILS_PLUGINS.each{ |path|
48         plugin_source = '../../../rails_plugins/'+path
49         plugin_dest   = 'vendor/plugins/'+path
50         # Ensure appropriate folder exists
51         m.directory plugin_dest
52         # Ensure appropriate folder exists
53         m.folder plugin_source, plugin_dest
54       }
55
56       # Copy every Rails script with exec persmissions.
57       m.directory 'script'
58       m.directory 'script/performance'
59       m.directory 'script/process'
60       %w( about breakpointer console destroy generate performance/benchmarker performance/profiler performance/request process/reaper process/spawner process/inspector runner server plugin spec spec_server).each do |file|
61         m.file "script/#{file}", "script/#{file}", script_options
62       end
63
64       # Picolena configuration files
65       m.template '../config/environment.rb', 'config/environment.rb', :assigns => {:version => Picolena::VERSION::STRING}
66       m.file '../config/white_list_ip.yml', 'config/custom/white_list_ip.yml'
67       m.file '../config/basic.rb', 'config/custom/picolena.rb'
68       m.template '../config/indexed_directories.yml', 'config/custom/indexed_directories.yml', :assigns => {:directories_to_index => @directories_to_index}
69       m.template '../config/title_and_names_and_links.yml', 'config/custom/title_and_names_and_links.yml', :assigns => {:version => Picolena::VERSION::STRING}
70       m.file '../config/icons_and_filetypes.yml', 'config/custom/icons_and_filetypes.yml'
71       m.file '../config/indexing_performance.yml', 'config/custom/indexing_performance.yml'
72
73       # README, License & Rakefile
74       m.file 'MIT-LICENSE', 'LICENSE'
75       m.file '../../../README.txt', 'README'
76       m.file '../../../README.txt', 'doc/README_FOR_APP'
77       m.file 'Rakefile', 'Rakefile'
78
79       unless options[:no_index]
80         # Indexing documents for development environment
81         m.rake 'index:create'
82         # Mirroring Ferret development index instead of indexing documents again for production.
83         m.mirror 'tmp/ferret_indexes/development', 'tmp/ferret_indexes/production'
84       end
85
86       # Launching specs
87       m.rake 'spec' unless options[:no_spec]
88
89       # Cleaning up temp folder if --spec-only
90       m.clean if options[:spec_only]
91     end
92   end
93
94   protected
95     def banner
96       <<-EOS
97 Creates a documents search engine
98
99 USAGE: #{spec.name} directory_to_be_indexed and_other_dirs_if_you_want
100 EOS
101     end
102
103     def add_options!(opts)
104       opts.separator ''
105       opts.separator 'Options:'
106       # For each option below, place the default
107       # at the top of the file next to "default_options"
108       # opts.on("-a", "--author=\"Your Name\"", String,
109       #         "Some comment about this option",
110       #         "Default: none") { |options[:author]| }
111       opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
112       opts.on("-d", "--destination=path", "Specify destination path (default: 'picolena')"){|options[:destination]|}
113       opts.on(nil, "--no-spec", "Install picolena without launching specs."){options[:no_spec]=true}
114       opts.on(nil, "--no-index", "Install picolena without indexing documents."){options[:no_index]=true}
115       opts.on(nil, "--spec-only", "Test picolena framework without installing it."){
116         options[:spec_only]=true
117         options[:no_index]=true
118         options[:destination]=File.join(Dir::tmpdir,"picolena_test_#{Time.now.to_i}")
119       }
120     end
121
122     def extract_options
123       # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
124       # Templates can access these value via the attr_reader-generated methods, but not the
125       # raw instance variable value.
126       # @author = options[:author]
127     end
128
129     # Installation skeleton.  Intermediate directories are automatically
130     # created so don't sweat their absence here.
131     BASEDIRS = %w(
132     app/controllers
133     app/helpers
134     app/models
135     app/views
136     app/views/documents
137     app/views/layouts
138     config
139     config/environments
140     config/initializers
141     config/custom
142     doc
143     lang/ui
144     lib
145     lib/plain_text_extractors
146     lib/tasks
147     log
148     public
149     public/help
150     public/images
151     public/images/icons
152     public/images/flags
153     public/javascripts
154     public/stylesheets
155     spec
156     spec/controllers
157     spec/fixtures
158     spec/helpers
159     spec/models
160     spec/test_dirs
161     spec/test_dirs/empty_folder
162     spec/test_dirs/indexed
163     spec/test_dirs/indexed/basic
164     spec/test_dirs/indexed/different_encodings
165     spec/test_dirs/indexed/just_one_doc
166     spec/test_dirs/indexed/lang
167     spec/test_dirs/indexed/literature
168     spec/test_dirs/indexed/others
169     spec/test_dirs/indexed/others/nested
170     spec/test_dirs/indexed/yet_another_dir
171     spec/test_dirs/not_indexed
172     spec/views
173     tmp/cache
174     tmp/ferret_indexes
175     tmp/pids
176     tmp/sessions
177     tmp/sockets
178     )
179
180     RAILS_PLUGINS=%w(
181     globalite
182     globalite/data
183     globalite/lang
184     globalite/lang/rails
185     globalite/lib
186     globalite/lib/globalite
187     globalite/lib/rails
188     globalite/rdoc
189     globalite/rdoc/classes
190     globalite/rdoc/classes/ActionView
191     globalite/rdoc/classes/ActionView/Helpers
192     globalite/rdoc/classes/ActiveRecord
193     globalite/rdoc/classes/Globalite
194     globalite/rdoc/files
195     globalite/rdoc/files/lib
196     globalite/rdoc/files/lib/globalite
197     globalite/rdoc/files/lib/rails
198     globalite/spec
199     globalite/spec/helpers
200     globalite/spec/lang
201     globalite/spec/lang/rails
202     globalite/spec/lang/ui
203     globalite/tasks
204     haml
205     rspec
206     rspec/autotest
207     rspec/bin
208     rspec/examples
209     rspec/examples/pure
210     rspec/examples/stories
211     rspec/examples/stories/game-of-life
212     rspec/examples/stories/game-of-life/behaviour
213     rspec/examples/stories/game-of-life/behaviour/examples
214     rspec/examples/stories/game-of-life/behaviour/stories
215     rspec/examples/stories/game-of-life/life
216     rspec/examples/stories/steps
217     rspec/failing_examples
218     rspec/lib
219     rspec/lib/autotest
220     rspec/lib/spec
221     rspec/lib/spec/example
222     rspec/lib/spec/expectations
223     rspec/lib/spec/expectations/differs
224     rspec/lib/spec/expectations/extensions
225     rspec/lib/spec/extensions
226     rspec/lib/spec/interop
227     rspec/lib/spec/interop/test
228     rspec/lib/spec/interop/test/unit
229     rspec/lib/spec/interop/test/unit/ui
230     rspec/lib/spec/interop/test/unit/ui/console
231     rspec/lib/spec/matchers
232     rspec/lib/spec/mocks
233     rspec/lib/spec/mocks/extensions
234     rspec/lib/spec/rake
235     rspec/lib/spec/runner
236     rspec/lib/spec/runner/formatter
237     rspec/lib/spec/runner/formatter/story
238     rspec/lib/spec/story
239     rspec/lib/spec/story/extensions
240     rspec/lib/spec/story/runner
241     rspec/plugins
242     rspec/plugins/mock_frameworks
243     rspec/pre_commit
244     rspec/pre_commit/lib
245     rspec/pre_commit/lib/pre_commit
246     rspec/pre_commit/spec
247     rspec/pre_commit/spec/pre_commit
248     rspec/rake_tasks
249     rspec/spec
250     rspec/spec/autotest
251     rspec/spec/spec
252     rspec/spec/spec/example
253     rspec/spec/spec/expectations
254     rspec/spec/spec/expectations/differs
255     rspec/spec/spec/expectations/extensions
256     rspec/spec/spec/extensions
257     rspec/spec/spec/interop
258     rspec/spec/spec/interop/test
259     rspec/spec/spec/interop/test/unit
260     rspec/spec/spec/interop/test/unit/resources
261     rspec/spec/spec/matchers
262     rspec/spec/spec/mocks
263     rspec/spec/spec/package
264     rspec/spec/spec/runner
265     rspec/spec/spec/runner/formatter
266     rspec/spec/spec/runner/formatter/story
267     rspec/spec/spec/runner/resources
268     rspec/spec/spec/runner/spec_parser
269     rspec/spec/spec/story
270     rspec/spec/spec/story/extensions
271     rspec/spec/spec/story/runner
272     rspec/stories
273     rspec/stories/example_groups
274     rspec/stories/interop
275     rspec/stories/pending_stories
276     rspec/stories/resources
277     rspec/stories/resources/helpers
278     rspec/stories/resources/matchers
279     rspec/stories/resources/spec
280     rspec/stories/resources/steps
281     rspec/stories/resources/stories
282     rspec/stories/resources/test
283     rspec/story_server
284     rspec/story_server/prototype
285     rspec/story_server/prototype/javascripts
286     rspec/story_server/prototype/lib
287     rspec/story_server/prototype/stylesheets
288     rspec_on_rails
289     rspec_on_rails/generators
290     rspec_on_rails/generators/helpers
291     rspec_on_rails/generators/rspec
292     rspec_on_rails/generators/rspec/templates
293     rspec_on_rails/generators/rspec/templates/script
294     rspec_on_rails/generators/rspec_controller
295     rspec_on_rails/generators/rspec_controller/templates
296     rspec_on_rails/generators/rspec_model
297     rspec_on_rails/generators/rspec_model/templates
298     rspec_on_rails/generators/rspec_scaffold
299     rspec_on_rails/generators/rspec_scaffold/templates
300     rspec_on_rails/lib
301     rspec_on_rails/lib/autotest
302     rspec_on_rails/lib/spec
303     rspec_on_rails/lib/spec/rails
304     rspec_on_rails/lib/spec/rails/example
305     rspec_on_rails/lib/spec/rails/extensions
306     rspec_on_rails/lib/spec/rails/extensions/action_controller
307     rspec_on_rails/lib/spec/rails/extensions/action_view
308     rspec_on_rails/lib/spec/rails/extensions/active_record
309     rspec_on_rails/lib/spec/rails/extensions/spec
310     rspec_on_rails/lib/spec/rails/extensions/spec/example
311     rspec_on_rails/lib/spec/rails/extensions/spec/matchers
312     rspec_on_rails/lib/spec/rails/matchers
313     rspec_on_rails/spec
314     rspec_on_rails/spec/rails
315     rspec_on_rails/spec/rails/autotest
316     rspec_on_rails/spec/rails/example
317     rspec_on_rails/spec/rails/extensions
318     rspec_on_rails/spec/rails/matchers
319     rspec_on_rails/spec/rails/mocks
320     rspec_on_rails/spec_resources
321     rspec_on_rails/spec_resources/controllers
322     rspec_on_rails/spec_resources/helpers
323     rspec_on_rails/spec_resources/views
324     rspec_on_rails/spec_resources/views/controller_spec
325     rspec_on_rails/spec_resources/views/render_spec
326     rspec_on_rails/spec_resources/views/rjs_spec
327     rspec_on_rails/spec_resources/views/tag_spec
328     rspec_on_rails/spec_resources/views/view_spec
329     rspec_on_rails/spec_resources/views/view_spec/foo
330     rspec_on_rails/stories
331     rspec_on_rails/stories/steps
332     rspec_on_rails/tasks
333 )
334 end
Note: See TracBrowser for help on using the browser.