Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mhickman84 committed Dec 19, 2010
1 parent 450d49c commit 115889f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ In a rails project this generator creates:
You can then use these directories to write your own dictionaries, class
extensions, forgeries, and formats.


Forgery will first look here for dictionaries and formats, so you can override
the ones used in the plugin.

Expand All @@ -54,6 +55,19 @@ See the forgeries in the plugin for examples of how to write your own.
See which dictionaries each forgery uses to override them with your own.


The Rails 3 plugin also registers a rake task which can generate new dictionaries
from html or xml on the web.

Writes to '${RAILS_ROOT}/lib/forgery/dictionaries' by default
(this can be overriden by setting Forgery::FileWriter#write_to!)

Parameters:
:dictionary_name -- the name of your new dictionary file
:source_url -- web page containing the data for your dictionary file
:css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data

Usage:
rake create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
## Examples

Here I'll supply a few examples of how it works, in general. See each forgery
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ end

desc %q{
Create a dictionary file from web content (xml or html).
Writes to the directory specified by Forgery::FileWriter#write_to!
'${GEM_HOME}/lib/forgery/dictionaries' by default (standalone)
'${RAILS_ROOT}/lib/forgery/dictionaries' by default (as a Rails 3 plugin)
Parameters:
:dictionary_name -- the name of your new dictionary file
:source_url -- web page containing the data for your dictionary file
:css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
Usage:
rake create_dictionary[test,'http://www.html_or_xml_page.com','li']
rake create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
}
task :create_dictionary, :dictionary_name, :source_url, :css_or_xpath do |t, args|
dictionary_name = args[:dictionary_name].to_s || raise("parameter :dictionary_name is required")
Expand Down
4 changes: 2 additions & 2 deletions lib/forgery/file_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def self.create_dictionary(dictionary_name, source_url, *css_or_xpath)
end

# Path to which new dictionaries will be written
# './dictionaries' by default
# '${GEM_HOME}/lib/forgery/dictionaries' by default
def self.write_path
@@write_path
end

# sets path to which new dictionaries will be written
# Sets path to which new dictionaries will be written
def self.write_to!(path)
@@write_path = File.expand_path path
end
Expand Down
16 changes: 15 additions & 1 deletion lib/forgery/forgery_railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@ class ForgeryRailtie < Rails::Railtie

rake_tasks do
namespace :forgery do
desc %q{
Create a dictionary file from web content (xml or html).
Writes to the directory specified by Forgery::FileWriter#write_to!
'${GEM_HOME}/lib/forgery/dictionaries' by default (standalone)
'${RAILS_ROOT}/lib/forgery/dictionaries' by default (as a Rails 3 plugin)
Parameters:
:dictionary_name -- the name of your new dictionary file
:source_url -- web page containing the data for your dictionary file
:css_or_xpath -- css or xpath selector(s) to element(s) containing the desired data
Usage:
rake forgery:create_dictionary[name_of_file,'http://www.html_or_xml_page.com','li']
}
task :create_dictionary, :dictionary_name, :source_url, :css_or_xpath do |t, args|
dictionary_name = args[:dictionary_name].to_s || raise("parameter :dictionary_name is required")
source_url = args[:source_url].to_s || raise("parameter :source_url is required")
css_or_xpath = args[:css_or_xpath].to_s || raise("parameter :css_or_xpath is required")

Forgery::FileWriter.write_to! "#{Rails.root}/lib/forgery/dictionaries"
Forgery::FileWriter.create_dictionary dictionary_name, source_url, css_or_xpath
end
Expand Down

0 comments on commit 115889f

Please sign in to comment.