当前位置: 首页 > 工具软件 > Rhodes > 使用案例 >

Rhodes入门教程-程序生成器(Generator)

闻安宜
2023-12-01

Rhodes程序生成器

 

Rhodes框架中实用的工具就是程序生成器,用户可以用它创建Rhodes应用程序,模型和测试(规格)。

 

生成应用程序


应用程序名称作为一个参数被传递。生成器将会为你的应用程序生成默认的目录结构,并附带合理的默认值。

Usage: rhodes app [options] [args]

Generate a new rhodes application.

 

Required:

name    - application name

 

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)

General 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


 

例如:

$ rhodes app myspace

生成目录结构如下:

myspace/

Rakefile

build.yml

rhoconfig.txt

./app:

application.rb

index.bb.erb

index.erb

layout.erb

loading.html

loading.png

./app/Settings:

controller.rb

home.bb.erb

home.erb

index.bb.erb

index.erb

login.bb.erb

login.erb

reset.bb.erb

reset.erb

wait.bb.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/jqtouch:

<jqtouch js script with some rhomobile fixes>

./public/js:

<default js libraries>

 

增加新模型

 

生成一个新的模型:

 

 

Usage: rhodes model [options] [args]

 

Generate a new model for a rhodes application.

 

Required:

name    - model name

attributes - list of one or more string attributes (i.e. name,industry,progress), NO spaces between attributes

 

General 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

 

例如:

$ cd myspace

$ rhodes model account name,industry

以上命令会在app/Account文件夹下生成以下文件:

app/Account/index.erb – the template to display the list of objects

app/Account/edit.erb – the template to edit an object

app/Account/new.erb – the template to supply values to create a new object

app/Account/show.erb – the template to displays the selected object

app/Account/index.bb.erb – the template to display the list of objects on Blackberry

app/Account/edit.bb.erb – the template to edit an object on Blackberry

app/Account/new.bb.erb – the template to supply values to create a new object on

Blackberry

app/Account/show.bb.erb – the template to displays the selected object on Blackberry

app/Account/account_controller.rb – contains the basic CRUD actions: index, new, create,

edit, update and delete.

app/Account/account.rb – contains Account model definition

app/test目录中会生成Account test specs预置文件:

app/test/account_spec.rb –Account test specs预置文件

增加测试框架

 

为应用程序增加测试框架:

 

 

Usage: rhodes spec

Add test framework to a rhodes application.

例如:

$ cd myspace

$ rhodes spec

这个命令会在程序目录中生成以下文件:

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

如果你要使用mspec,需将mspecfileutils扩充到build.yml文件中:

extensions: ["mspec", "fileutils"]

 

 类似资料: