data/tasks/setup.rb in bones-1.3.0 vs data/tasks/setup.rb in bones-1.3.1

- old
+ new

@@ -66,11 +66,13 @@ PROJ.svn_trunk = 'trunk' PROJ.svn_tags = 'tags' PROJ.svn_branches = 'branches' # Load the other rake files in the tasks folder -Dir.glob('tasks/*.rake').sort.each {|fn| import fn} +rakefiles = Dir.glob('tasks/*.rake').sort +rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact! +import(*rakefiles) # Setup some constants WIN32 = %r/win32/ =~ RUBY_PLATFORM unless defined? WIN32 DEV_NULL = WIN32 ? 'NUL:' : '/dev/null' @@ -113,12 +115,32 @@ # specified. # # changes = paragraphs_of('History.txt', 0..1).join("\n\n") # summary, *description = paragraphs_of('README.txt', 3, 3..8) # -def paragraphs_of(path, *paragraphs) - File.read(path).delete("\r").split(/\n\n+/).values_at(*paragraphs) +def paragraphs_of( path, *paragraphs ) + title = String === paragraphs.first ? paragraphs.shift : nil + ary = File.read(path).delete("\r").split(/\n\n+/) + + result = if title + tmp, matching = [], false + rgxp = %r/^=+\s*#{Regexp.escape(title)}/i + paragraphs << (0..-1) if paragraphs.empty? + + ary.each do |val| + if val =~ rgxp + break if matching + matching = true + rgxp = %r/^=+/i + elsif matching + tmp << val + end + end + tmp + else ary end + + result.values_at(*paragraphs) end # Adds the given gem _name_ to the current project's dependency list. An # optional gem _version_ can be given. If omitted, the newest gem version # will be used. @@ -128,24 +150,40 @@ version = spec.version.to_s if version.nil? and !spec.nil? PROJ.dependencies << (version.nil? ? [name] : [name, ">= #{version}"]) end -# Adds the given _path_ to the include path if it is not already there +# Adds the given arguments to the include path if they are not already there # -def ensure_in_path( path ) - path = File.expand_path(path) - $:.unshift(path) if test(?d, path) and not $:.include?(path) +def ensure_in_path( *args ) + args.each do |path| + path = File.expand_path(path) + $:.unshift(path) if test(?d, path) and not $:.include?(path) + end end # Find a rake task using the task name and remove any description text. This # will prevent the task from being displayed in the list of available tasks. # def remove_desc_for_task( names ) Array(names).each do |task_name| task = Rake.application.tasks.find {|t| t.name == task_name} next if task.nil? task.instance_variable_set :@comment, nil + end +end + +# Change working directories to _dir_, call the _block_ of code, and then +# change back to the original working directory (the current directory when +# this method was called). +# +def in_directory( dir, &block ) + curdir = pwd + begin + cd dir + return block.call + ensure + cd curdir end end # EOF