lib/tap/generator/generators/file_task/templates/task.erb in tap-0.9.1 vs lib/tap/generator/generators/file_task/templates/task.erb in tap-0.10.0
- old
+ new
@@ -1,40 +1,33 @@
-# == Description
-# Replace with a description. The default task reads
-# in the lines of a text file and dumps them as YAML
-# into a yaml file.
-# === Usage
-# Replace with usage instructions
+<% redirect do |target| %># <%= const.name %>::manifest <replace with manifest summary>
+# <replace with command line description>
+
+# <%= const.const_name %> Documentation
+# This example FileTask counts the specified letters
+# in a source file and writes the counts to a target
+# file as YAML.
#
-class <%= class_name_without_nesting %> < Tap::FileTask
- # use config to set task configurations
- # configs have accessors by default
-
- config :key, 'value' # a sample config
-
- # process defines what the task does; use the
- # same number of inputs to enque the task
- # as specified here
- def process(filepath)
+class <%= const.const_name %> < Tap::FileTask
- # infer an output filepath relative to the :data directory,
- # (this is convenient for testing) while changing the
- # basename of filepath to 'yml'. See FileTask#filepath
- # for filepaths based on the task name.
- target = app.filepath(:data, basename(filepath, '.yml') )
+ # <config file documentation>
+ config :letters, ['a','e','i','o','u'], &c.array # a list of letters to count
- # prepare ensures the parent directory for
- # output exists, and that output does not;
- # any existing file is backed up and reverts
- # in the event of an error
+ def process(source, target)
+
+ # prepare ensures the parent directory for target
+ # exists and, if necessary, backs up the existing
+ # target file (which is restored on error)
prepare(target)
-
+
# now perform the task...
- array = File.read(filepath).split(/\r?\n/)
+ str = File.read(source)
+ letter_count = letters.collect do |letter|
+ str.count(letter)
+ end
+
File.open(target, "wb") do |file|
- file << array.to_yaml
+ file << letter_count.to_yaml
end
-
+
target
end
-
-end
+end <% module_nest(const.nesting, ' ') { target } end %>
\ No newline at end of file