genosaurus 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,117 @@
1
+ =Hello, and welcome to Genosaurus!
2
+
3
+ Genosaurus is meant to be a very, very easy to use generation system for Ruby. It's simple and straightforward, yet offers plenty of flexibility in it's use. People use 'generators' all the time, and you either have to roll your own, or use some really cumbersome generator that some one else wrote, that is just way too difficult to use. Enter Genosaurus!
4
+
5
+ ==Installation
6
+ $ sudo gem install genosaurus
7
+
8
+ ==Getting Started
9
+
10
+ ===Implied Manifests
11
+ The easiest way to use Genosaurus is to let it do the work for you. Let's looked at what's called an 'implied' manifest:
12
+
13
+ dir:
14
+ simple_generator.rb
15
+ templates:
16
+ hello_world.txt.template
17
+
18
+ That's our folder structure. Now let's look at simple_generator.rb:
19
+
20
+ require 'rubygems'
21
+ require 'genosaurus'
22
+
23
+ class SimpleGenerator < Genosaurus
24
+ end
25
+
26
+ Now if we run that generator:
27
+
28
+ $irb: SimpleGenerator.run
29
+
30
+ We should get a file called hello_world.txt generated in the current directory. Yes, it truly is that simple!
31
+
32
+ With implied manifests our directory structure under 'templates' tells the whole story, and Genosaurus is smart enough to figure it out. All the file names, and the same goes for folders, need to end in .template, and Genosaurus will do the rest.
33
+
34
+ All the files will go through ERB before they generated, so you can put all your lovely little dynamic goodies in there. File, and folder, names also get run through ERB so you can even make the file name dynamic too!
35
+
36
+ Let's look at a more complex example:
37
+
38
+ dir:
39
+ complex_generator.rb
40
+ templates:
41
+ app:
42
+ views:
43
+ <%=param(:name).plural%>.template:
44
+ hello_world.html.erb
45
+ models:
46
+ <%=param(:name)%>.rb.template
47
+
48
+ Let's run our complex_generator.rb file:
49
+
50
+ require 'rubygems'
51
+ require 'genosaurus'
52
+
53
+ class ComplexGenerator < Genosaurus
54
+ require_param: name
55
+ end
56
+
57
+ Now if we run that generator:
58
+
59
+ $irb: ComplexGenerator.run("name" => "user")
60
+
61
+ Now you should end up with the following:
62
+
63
+ app:
64
+ views:
65
+ users:
66
+ hello_world.html.erb
67
+ models:
68
+ user.rb.template
69
+
70
+ In the ComplexGenerator we told Genosaurus that we are requiring that the parameter, name, be passed into it. We are then using that parameter to generate the names of some files and folders. Pretty cool, eh? See how simple that is.
71
+
72
+ Let's look at the manifest.yml file for our simple_generator example:
73
+
74
+ template_1:
75
+ type: file
76
+ template_path: <%= File.join(templates_directory_path, "templates", "hello_world.txt.template")
77
+ output_path: hello_world.txt
78
+
79
+ Pretty simple. We give the template a name, template_1, it really doesn't matter what it is, but Hash objects need keys. The 'type' parameter is either file or directory. The template_path is the path to the template. Finally, the output_path is the where you want the file to be generated.
80
+
81
+ Let's look at our more complex example. We can change the directory structure a bit, since we really don't need ERB in the file names now:
82
+
83
+ dir:
84
+ complex_generator.rb
85
+ templates:
86
+ hello_world.html.erb.template
87
+ model.rb.template
88
+
89
+ Our manifest.yml file would look like this:
90
+
91
+ hello_world_template:
92
+ type: file
93
+ template_path: <%= File.join(templates_directory_path, "templates", "hello_world.html.erb")
94
+ output_path: <%= File.join("app", "views", param(:name).plural, "hello_world.html.erb") %>
95
+ model_template:
96
+ type: file
97
+ template_path: <%= File.join(templates_directory_path, "templates", "model.html.erb")
98
+ output_path: <%= File.join("app", "models", "#{param(:name)}.rb") %>
99
+
100
+ This will generate the exact same thing as our implied manifest.
101
+
102
+ ===Explicit Manifests
103
+ Explicit manifests are used when there is a manifest.yml supplied at the same level as the generator. If there is a manifest.yml file then implied manifests are not used. This means you have to define the entire generation process. This is great if you have a pretty complicated generator, as the manifest.yml is also sent through ERB before being loaded.
104
+
105
+ ==Contact
106
+ Please mail bugs, suggestions and patches to <bugs@mackframework.com>.
107
+
108
+ On the web at: http://www.mackframework.com
109
+
110
+ ==License and Copyright
111
+ Copyright (C) 2008 Mark Bates, http://www.mackframework.com
112
+
113
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
114
+
115
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
116
+
117
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.