forked from kutirtech/kutir-rhodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.txt
198 lines (133 loc) · 8.1 KB
/
generator.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Rhodes Application Generator
You can use RhoStudio to create Rhodes applications and models in an Eclipse-like environment.
You can also use the Rhodes generator utility from the command line to create Rhodes applications, models, and tests (specs).
## Generating a Rhodes Application from RhoStudio
In RhoStudio, select File->New->Project...
The New Project window opens. Select the Rhodes application wizard and click the Next button.
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/new-project.png"/>
Enter the name for your Rhodes application in Project name; in this case, "storemanager". You may specify a specific folder for your destination where your project is stored, by default, the destination is your RhoStudio workspace folder. Then press the Finish button.
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/rhodes-application-wizard.png"/>
After pressing the Finish button, you'll see the Rhodes app generator script output in the output console (Rhomobile build console).
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/rhodes-app-generator-output.png"/>
The generated application has the following directory structure and files.
storemanager/
Rakefile
build.yml
rhoconfig.txt
./app:
application.rb
index.erb
layout.erb
loading.html
loading.png
./app/Settings:
controller.rb
home.erb
index.erb
login.erb
reset.erb
wait.erb
./app/helpers:
application_helper.rb
browser_helper.rb
./icon:
<default application icons; modify these to have your own app icon>
./public:
./public/css:
<default set of css for different platforms>
./public/images:
<default images used by js libraries>
./public/jquery:
<jQuery js script with some rhomobile fixes>
./public/jqmobile:
<jQuery Mobile js script with some rhomobile fixes>
./public/js:
<default js libraries>
## Adding a Model to a Rhodes Application from RhoStudio
Rhodes applications support a Model-View-Controller (MVC) pattern. To start our application, we will generate a Model. To generate a Rhodes model and create the associated Controller and View templates, right-click on the application project in the Project Explorer and select New->RhoMobile model.
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/menu-new-rhodes-model.png"/>
In the Model Information window, enter the name for your model: in this case, `Product`.
**NOTE: Do not use the following for model names: Config, Settings, helpers, test, Client, Sync, or any built-in Ruby class name. It is good programming practice to avoid using generic names, such as client, or time, or print.**
Also enter the Model attributes as a string with no spaces and each attribute separated by a comma: in this case, `name,brand,price,quantity,sku`. (Whitespaces at the field name beginning and end will be trimmed and whitespaces in the middle of the field name will be replaced with an underscore character.)
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/model-information.png"/>
After pressing the Finish button, you'll see the RhoMobile model generator script output in the output console (Rhodes build log console).
<img src="http://rhodocs.s3.amazonaws.com/rhostudio-tutorial/rhodes-model-generator-output.png"/>
You should now see a 'Product' folder below the 'app' folder in your storemanager application. These files constitute the Model, Views and Controller file for the Product Model we just created. The files are organized as follows:
This will generate the following files in the folder app/Account:
* app/Product/index.erb - the html view template to display the list of objects
* app/Product/edit.erb - the html view template to edit an object
* app/Product/new.erb - the html view template to supply values to create a new object
* app/Product/show.erb - the html view template to displays the selected object
* app/Product/product_controller.rb - contains the the business logic for the model, the basic CRUD actions: index, new, create, edit, update and delete.
* app/Product/product.rb - contains the Product model definition. Since we are using the default PropertyBag definition, we don't need to modify this file any further.
A placeholder for test specs will be generated in the app/test folder:
* app/test/product_spec.rb - placeholder for Account test specs
## Generating A Rhodes Application and Model
You can generate your Rhodes application and model from the command line.
### Generating a Rhodes Application from the Command Line
You can pass your application name to the rhodes app command as a parameter. The Rhodes utility will generate a default directory structure for your application, with default code for the generated files.
Usage: rhodes app name [options] [args]
Generate a new rhodes application.
Options:
--norhoconnect - don't include rhoconnect-client in application
Required:
name - application name
args (optional):
syncserver - url to the source adapter (i.e. "" or "http://myacct.rhohub.com/apps/myapp/sources/")
zip_url - optional url to zipfile download of bundle (this can be your RhoHub Bundle URL)
options:
-p, --pretend Run, but do not make any changes.
-f, --force Overwrite files that already exist.
-s, --skip Skip files that already exist.
-d, --delete Delete files that have previously been generated with this generator.
--no-color Don't colorize the output
-h, --help Show this message
--debug Do not catch errors
### Adding a Model to Your Rhodes Application from the Command Line
Once you have generated your application, you can add a model to it, and the model can have attributes. For example, if you have a store application, you can add a model named product, and attributes like brand, name, price, and quantity.
Usage: rhodes model [options] [args]
Generate a new model for a rhodes application.
args:
name - model name
attributes - list of one or more attributes (i.e. name,industry,progress), NO spaces between attributes
options:
-p, --pretend Run, but do not make any changes.
-f, --force Overwrite files that already exist.
-s, --skip Skip files that already exist.
-d, --delete Delete files that have previously been generated with this generator.
--no-color Don't colorize the output
-h, --help Show this message
--debug Do not catch errors
For example, here is the command to generate a model named account, with the attributes name and industry.
:::term
$ cd myspace
$ rhodes model account name,industry
### Adding a Native extension to Your Rhodes Application from the Command Line
Once you have generated your application, you can add a native extension to it.
Usage: rhodes extension [args]
Generate a new native extension for a rhodes application.
args:
name - extension name
For example, here is the command to generate a model named account, with the attributes name and industry.
:::term
$ cd myspace
$ rhodes extension Nanovisor
## Adding Test Framework
To add a test framework to the application:
Usage: rhodes spec
Add test framework to a rhodes application.
For example:
:::term
$ cd myspace
$ rhodes spec
This will generate the following files in the app folder:
* SpecRunner/controller.rb - contains index action, which start all tests
* SpecRunner/index.erb - the template to display tests results
* mspec.rb - contain all mspec required files
* spec_runner.rb - contain spec framework initialization and generate list of spec files
If you are going to use mspec, then add mspec and fileutils extensions to your application's build.yml file:
extensions: ["mspec", "fileutils"]
To run the tests you need to add a link to the SpecRunner controller in your index.erb:
:::html
<li><a href="SpecRunner">Run tests</a></li>
Once you click the link a summary of the results with number of passing/failing tests will be displayed on the screen.