没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > limber-plugin |
limber-plugin
|
0 | 0 | 25 |
贡献者 | 讨论 | 代码提交 |
MOVED TO GITHUBhttp://github.com/stalcottsmith/limber/tree/master
git://github.com/stalcottsmith/limber.git
WARNING: Experimental...
LimberBending Flex to Rails.
What Does It Do?This Rails plugin provides a two-stage active code generator for Adobe Flex applications which interact with a Rails resource on the back end. The input to the generator is a Ruby DSL along with a number of helpers (behaviors and components) to help keep your code dry.
This allows Ruby developers to utilize the full UI widget library for Flex to develop Rich Internet Applications with relatively few lines of Ruby. It provides generators and rake tasks to produce the entire application using the Cairngorm framework. I tried to remain faithful to the general ideas contained in the example application in the Flexible Rails book, however, having produced one entire production application this way, I am thinking about refactoring and possibly generating code using a different framework.
There should be no need to modify the generated code except in some cases where you may wish to test or debug something. As such, it is an "active" code generator. You only maintain Ruby code.
You may include arbitrary ActionScript where needed, however, when you find yourself dropping into ActionScript more than once for the same type of thing, it is advisable to extend Limber by adding a Behavior or a Component. (The names for these abstractions may change.)
So far I have developed a couple components such as:
form_for data_grid_for create_or_update_buttons_for and so on. These are really more analogous to Rails helpers so I am a little unhappy overloading the term "component."
Behaviors include:
for_each create update destroy reorder alert filter_on_boolean_value format_currency format_date and more...
Example CodeUsage of data_grid_for def users_list_panel
panel :title => "User List", :id => :userListPanel,
:background_alpha => 0.15, :height => "100%", :width => "50%",
:status => "({_model.users.length}) Users" do
data_grid_for(:users, :id => :usersDG,
:background_alpha => 0.15, :width => "100%", :height => "100%",
:item_click => "userSelectionChanged(event)" ) do |grid|
grid.column "ID", :id, :width => 30
grid.column "Logon Name", :logon_name, :width => 145
grid.column "Name", :known_as_name, :width => 145
grid.column "Company", :company_name, :width => 200
end
end
endUsage of form_for def user_data_form
v_box('Details', :height => "100%", :width => "100%") {
form_for( :user, :truth_values => ['Y', 'N'] ) do |f|
f.heading "{_model.currentUser == null ? 'Enter new user' : 'Update existing user' }"
f.text "First Name", :first_name
f.text "Last Name", :last_name
f.text "Logon Username", :logon_name, :required => true, :max_chars => 50
f.text "Password", :password, :display_as_password => true, :max_chars => 50, :text => "{null}"
f.text "Confirm Password", :password_confirmation, :display_as_password => true,
:max_chars => 50, :text => "{null}"
f.text "Email Address", :email_address
f.check "Internal User?", :is_internal_user
f.combo "Company", :company_id, :label_field => 'name', :width => 225,
:collection => :companies, :label_function => "companyStateAndName"
f.button_bar {
create_or_update_buttons_for(:user, :cancel => "_model.currentUser = null ; #{f.clear}",
:create => f.form_values, :after_create => f.clear,
:update => f.form_values.merge(:id => model_value(:user, :id)),
:after_update => f.clear)
button "Delete", :click => "deleteClickHandler(event) ; #{f.clear}",
:enabled => bind_to("_model.currentUser != null")
}
end
}
endAs you can see, some ActionScript is required but I have tried to make it as minimal as possible.
Why?The impetus for development of this plugin came in the form a consulting project. I was contacted about an application using Ruby on Rails and Flex which had been in development for quite some time and was way behind schedule. They were seeking to on-shore the development and get the project into production in six weeks.
I did not know Flex but I was intrigued and immediately began to review the Flexible Rails example application and related Flex documentation. In the end, I was able to rewrite the entire application from scratch, replacing 30,000 lines of hand coded MXML and ActionScript with about 3000 lines of ruby, including a minimal amount of ActionScript. This seemed to me to be a far more maintainable code base. I was able to do this in two months, while developing the plugin. I am convinced the value of Code Generation cannot be underestimated. Furthermore, Ruby is a fantastic language for writing code generators.
Under Active DevelopmentThis code is under active development and may not work. There are parts which are not yet included. Documentation is so far, non-existent, however, you are welcome to take a peek.
Known IssuesI know there are places where I am not doing things the best way and have been sloppy. There is cruft that needs to be removed. The main method in FlexMXMLComponent needs to be cleaned up. Debugging behaviors could be a lot easier. I know that I have been inconsistent in some of my meta-programming techniques and I look forward to cleaning up based on what I have learned.
Please be forgiving. I developed this primarily as a tool for myself under heavy deadline pressure to make an impossible project just barely possible. It worked. I think there is considerable value in this approach and I plan to clean this up, document it and release a screencast and example application in May or June.
Stay tuned.