`
dcaoyuan
  • 浏览: 306396 次
社区版块
存档分类
最新评论

From Rails to Erlyweb - Part II

阅读更多

Updated Aug 23: Please see From Rails to Erlyweb - Part II Manage Project - Reloaded

Updated July 15: store the database configuration in <opaque> session of yaws.conf

Updated May 2: erlweb:compile(AppDir::string(), Options::[option()]) has option: {auto_compile, Val}, where Val is 'true', or 'false'. In case of development, you can turn on {auto_compile, true}. So, you only need to run erlyweb_app:boot(myapp) once.

2. Manage project

Erlyweb provides erlyweb:compile(App, ..) to compile the source files under app directory. To start an app, you usually should erlydb:start(mysql, ....) and compile app files first. To make life easy, you can put some scripting like code under myproject\script directory. Here's my project source tree:

myproject
  + apps
  |   + myapp
  |       + ebin   
  |       + include
  |       + nbproject
  |       + src
  |           + components
  |           + lib
  |           + services
  |       + test
  |       + www
  + config
  |   * yaws.conf
  + script
      + ebin
      + src
           * erlyweb_app.erl

Where, config/yaws.conf contains the confsiguration that will copy/paste to your real yaws.conf file. Here's mine:

## This is the configuration of apps that will copy/paste to your yaws.conf.

ebin_dir = D:/myapp/trunk/script/ebin
ebin_dir = D:/myapp/trunk/apps/myapp/ebin

<server localhost>
  port = 8000
  listen = 0.0.0.0
  docroot = D:/myapp/trunk/apps/myapp/www
  appmods = </myapp, erlyweb>
  <opaque>
    appname = myapp
    hostname = "localhost"
    username = "mememe"
    password = "pwpwpw"
    database = "myapp_development"  
        </opaque>
</server>

You may have noticed, all beams under D:/myapp/trunk/script/ebin and D:/myapp/trunk/apps/myapp/ebin will be auto-loaded by yaws.

erlyweb_app.erl is the boot scripting code, which will be used to start db connection and compile the code. Currently I run these scripts manually. I'll talk later.

-module(erlyweb_app).

-export([start/1]).

-export([main/1, 
   boot/1, 
   build/1, 
   decompile/2
        ]).

-include("yaws.hrl").

%% @doc call back funtion when yaws start an app  
%% @see man yaws.conf
%%      start_mod = Module
%%          Defines  a  user  provided  callback  module.  At startup of the
%%          server, Module:start/1 will  be  called.   The  #sconf{}  record
%%          (defined  in  yaws.hrl) will be used as the input argument. This
%%          makes it possible for  a  user  application  to  syncronize  the
%%          startup  with  the  yaws  server as well as getting hold of user
%%          specific  configuration  data,  see  the  explanation  for   the
%%          

To build it,

> erlc -I /opt/local/lib/yaws/include erlyweb_app.erl

The erlyweb_app.erl is almost escript ready, but I use it as module functions currently. It's pre-compiled and erlyweb_app.beam is placed under script/ebin

So, I start myapp by steps:

cd \myproject
yaws -i -sname yaws
1> erlyweb_app:build(myapp).

The erlyweb_app.erl is almost escript ready, but I use it as module functions currently. It's pre-compiled and erlyweb_app.beam is placed under script/ebin

After I made changes to myapp, I run above erlyweb_app:build(myapp). again, then everything is up to date.

This is surely not the best way to handle the write-compile-run-test cycle, I'll improve the scripting to let starting yaws as a node, then hot-swap the compiled code to it.

It's a good experience to play with Rails, I like rake db:migrate, script, config folders of Rails. And Grails also brings some good idea to manage web app project tree. I'll try to bring them into project manager of ErlyBird.

Next part, I'll talk about the magic behind Erlyweb, and why I prefer the magic of Erlyweb to Rails.

分享到:
评论

相关推荐

    rails-dev-box, 面向 Ruby on Rails 核心开发的虚拟机.zip

    rails-dev-box, 面向 Ruby on Rails 核心开发的虚拟机 用于 Ruby on Rails 核心开发的虚拟机简介注意:这个虚拟机不是为 Rails 应用程序开发而设计的,只是为。 这个项目自动设置开发环境,以便在 Ruby on Rails ...

    rails-documentation-2-0-2

    rails-documentation-2-0-2

    rails-beginner-s-guide

    rails-beginner-s-guide是Rails 指导手册,帮组学习了解rails开发

    rails-dev-box:用于Ruby on Rails核心开发的虚拟机

    用于Ruby on Rails核心开发的虚拟机 介绍 请注意,该虚拟机并非为...host $ cd rails-dev-box host $ vagrant up 而已。 安装完成后,您可以使用以下命令访问虚拟机: host $ vagrant ssh Welcome to Ubuntu 20.10

    sclo-ror42-rubygem-rails-html-sanitizer-1.0.3-1.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    rails应用--导航栏实例工程

    在本项目"rails应用--导航栏实例工程"中,我们将探讨如何在Ruby on Rails框架下构建一个实用的导航栏。Rails是一个流行的开源Web应用程序框架,它遵循MVC(模型-视图-控制器)架构模式,使得开发过程更加高效且结构...

    rails-documentation-1-2-1.zip

    标题 "rails-documentation-1-2-1.zip" 暗示这是一份关于 Ruby on Rails 框架的文档,版本为 1.2.1。Ruby 是一种面向对象的编程语言,而 Rails 是一个基于 Ruby 的开源 Web 应用程序框架,遵循 Model-View-...

    rails-documentation-1-2-0-rc1.chm

    rails-documentation-1-2-0-rc1.chm

    rails-react-components-源码.rar

    本文将深入探讨"rails-react-components-源码.rar"中的关键知识点,帮助开发者理解如何在Rails应用中集成React组件。 1. **React组件化开发** React的核心概念是组件,它允许我们将UI拆分为独立、可重用的部分。在...

    rails-ftw-v0.18-2.1.5-4.1.8

    rails-ftw-v0.18-2.1.5-4.1.8.exe用于在windows环境下搭建readmine环境

    rails-2.1.0-gem

    "rails-2.1.0-gem"是Rails框架的一个特定版本,即2.1.0的gem包,用于在Ruby环境中安装和管理Rails框架。 Rails的核心理念是“约定优于配置”(Convention over Configuration),这意味着开发者可以遵循一套预设的...

    rails-chm-2-0-2.rar

    `rails-documentation-2-0-2.chm` 文件详细涵盖了这些概念,包含了关于Rails 2.0.2的API参考、教程和指南。通过仔细阅读和实践,开发者能够深入理解Rails的工作原理,并有效地开发出高效、可维护的Web应用。

    rails-development-environment-master.rar

    标题 "rails-development-environment-master.rar" 暗示这是一个关于Ruby on Rails开发环境的压缩包。Rails是基于Ruby语言的一个开源Web应用框架,遵循MVC(Model-View-Controller)架构模式,广泛用于构建数据库...

    rails-yelp-mvp-源码.rar

    【标题】"rails-yelp-mvp-源码" 指的是一个基于Rails框架开发的类似于Yelp(美国知名餐饮评论网站)的最小可行产品(Minimum Viable Product, MVP)的源代码。Rails是Ruby编程语言的一个流行Web开发框架,以其“约定...

    rails-playlists-源码.rar

    "rails-playlists-源码"很可能是某个开发者或团队分享的关于音乐播放列表管理功能的示例代码或项目。在本文中,我们将深入探讨Rails框架的基本概念,以及如何通过源码理解其在实现播放列表功能时的核心技术。 1. **...

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    ### Ruby on Rails Guides v2 - Ruby on Rails 4.2.5 #### 一、重要概念及基础假设 - **重要概念**:本指南旨在帮助读者深入理解Ruby on Rails(以下简称Rails)4.2.5版本的核心功能与最佳实践。 - **基础假设**:...

    rails-nginx-passenger-ubuntu, 关于如何在 Nginx 8.04服务器上启动和运行和乘客的说明.zip

    rails-nginx-passenger-ubuntu, 关于如何在 Nginx 8.04服务器上启动和运行和乘客的说明 rails-nginx-passenger-ubuntu我关于用 ubuntu 。Nginx 。乘客和mysql建立 Rails的简单制作服务器的笔记。别名echo"alias ll='...

    Ajax-Rails-4-AJAX-Form.zip

    Ajax-Rails-4-AJAX-Form.zip,rails 4 ajax表单示例,ajax代表异步javascript和xml。它是多种web技术的集合,包括html、css、json、xml和javascript。它用于创建动态网页,其中网页的小部分在不重新加载网页的情况下...

    rails-event-sourcing-example, 带有RabbitMQ的Rails 事件.zip

    rails-event-sourcing-example, 带有RabbitMQ的Rails 事件 RabbitMQ事件源示例 运行示例 1确保已经安装并运行 RabbitMQ在macosx上,你可以使用 Homebrew 安装 RabbitMQ$ brew install rabbitmq开始使用$/u

    railstutorial3rd-1.0.2

    railstutorial3rd-1.0.2 分享给大家了

Global site tag (gtag.js) - Google Analytics