Giter VIP home page Giter VIP logo

shaunr0b / serve Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jlong/serve

1.0 1.0 0.0 463 KB

Serve is a small Rack-based web server and rapid prototyping framework for Web applications (specifically Rails apps). It is designed to compliment web application development and enforce a strict separation of concerns between designer and developer. Using Serve allows the designer to work in a separate prototype project, while the developer can work on the actual application and utilize resources from the prototype as needed. This allows the designer to focus on presentation and flow, while the developer can focus on implementation.

License: Other

serve's Introduction

Serve - A Rapid Prototyping Framework for Web Applications

Serve is a small Rack-based web server that makes it easy to serve HTML, ERB, or HAML from any directory.

But Serve is much more than a simple web server.

Serve’s primary purpose is to provide a rapid prototyping framework for Web applications (specifically Rails apps). It is designed to compliment web application development and enforce a strict separation of concerns between designer and developer. Using Serve allows the designer to work in a separate prototype project, while the developer can work on the actual application and utilize resources from the prototype as needed. This allows the designer to focus on presentation and flow, while the developer can focus on implementation.

This “Design First” approach can help a designer identify and fix a large number of problems before a feature is ever touched by the developer. Once a feature has been completed in the prototype project it can also be estimated with a high degree of accuracy.

A Serve prototype can work much like the finished application and be virtually indistinguishable. The only difference being that state is not saved as a user clicks around.

Serve can be used alongside any Web development framework, but Rails developers will find it especially familiar. One way of thinking about Serve is that it is essentially a Rails application with only one part of the Rails MVC stack – the views. Serve basically allows you to have a separate project just for designing the views for the application. When views are ready, they can be copied over from the prototype to the application almost as is. This process is eased since Serve has full support for partials and layouts with either ERB or HAML. Serve can also handle SASS, Textile, and Markdown if the appropriate libraries are installed.

Installation

Serve is distributed as a Ruby gem and can be installed from the command prompt. Just type:

gem install serve

Some systems, like the Mac, may require that you type:

sudo gem install serve

If you are a Mac user and are new to the command prompt see:

wiseheartdesign.com/articles/2010/11/12/the-designers-guide-to-the-osx-command-prompt/

Google “command prompt windows” if you are on a PC to find a simple tutorial.

Usage

Once the gem is installed the ‘serve` command will be available from the command prompt. To launch Serve, just type the command and press enter:

serve

This will launch a simple web server which you can access from any web browser at the following address:

http://localhost:4000

Once the server is going it will output a running log of its activity. To stop the server at any time, type CTRL+C at the command prompt. By default the serve command serves up files from the current directory. To change this behavior, ‘cd` to the appropriate directory before starting serve or pass the directory as the final parameter to the command:

serve project_directory

The ‘serve` command automatically binds to 0.0.0.0 (localhost) and uses port 4000 by default. To serve files over a different IP (that is bound to your computer) or port specify those options on the command line:

serve 4000               # a custom port

serve 192.168.1.6        # a custom IP

serve 192.168.1.6:4000   # a custom IP and port

For your convenience if the file “script/server” exists in the current directory the serve command will start that instead of launching a Ruby Web server. You can specify the environment that you want to start the server with as an option on the command line:

serve production         # start script/server in production mode

Creating a New Serve Project

For simple projects, you don’t need to structure your files in a specific way. All ERB, Haml, and Sass files will be processed wherever they are found in the project root. But for more complex projects you may want to use Serve with a ‘config.ru` file so that you can take advantage of other Rack middleware and structure the project in a Rack compatible way.

To create a new Rack-based Serve project in the “mockups” directory, type the following on the command line:

serve create mockups   # create a new project in the mockups directory

This will create a new project with the following directory structure:

mockups/
  |
  +-- config.ru              # Rack configuration file
  |
  +-- compass.config         # Compass configuration file
  |
  +-- public/                # Directories for static assets
  |    |
  |    +-- stylesheets/      # Compiled stylesheets
  |    |
  |    +-- images/
  |    |
  |    `-- javascripts/
  |
  +-- sass/                  # Store Sass source files here
  |    |
  |    `-- application.sass  # Example Sass file for application
  |
  +-- tmp/                   # Needed for Passenger (mod_passenger)
  |    |
  |    `-- restart.txt
  |
  `-- views/                 # Store your ERB, Haml, etc. here
       |
       +-- _layout.html.erb  # Example layout
       |
       +-- hello.html.erb    # Example view
       |
       `-- view_helpers.rb   # Example view helpers

If you would like to generate the project with a specific JavaScript framework you can do so with the -j flag:

serve create mockups -j prototype

Available frameworks are: jquery, jquery-ui, mootools, prototype, and scriptaculous.

The ‘serve create` command can be executed multiple times or on an existing project without negative consequences.

Upgrading a Compass Project to a Serve Project

If you are a Compass user you can convert an existing Compass project to a Serve project with the “convert” sub-command:

serve convert mockups

This will rename and move a number of files for you and will turn your Compass project into a Serve project.

Note that after upgrading a Compass project, you will no longer need to use the ‘compass watch` command to generate your stylesheets. Your stylesheets will be compiled on the fly with Serve.

File Types

Serve presently does special processing for files with following extensions:

textile

Evaluates the document as Textile (requires the Redcloth gem)

markdown

Evaluates the document as Markdown (requires the Bluecloth gem)

erb

Experimental support for ERB

haml

Evaluates the document as Haml (requires the Haml gem)

sass

Evaluates the document as Sass (requires the Haml gem)

scss

Evaluates the document as SCSS (requires the Haml gem)

email

Evaluates the document as if it is an e-mail message; the format is identical to a plain/text e-mail message’s source

redirect

Redirects to the URL contained in the document

View Helpers

If you drop a file called “view_helpers.rb” in your views directory, you can define custom helpers for your Haml and ERB views. Just create a ViewHelpers module and define your helper methods there:

module ViewHelpers
  def custom_method
    "Request object: #{request.headers['user-agent']}"
  end
end

Helpers have full access to the request and response objects so you can easily read and manipulate headers.

More Information

You can find more information about Serve, including a detailed Screencast, on the GitHub wiki:

wiki.github.com/jlong/serve

All development takes place on GitHub:

github.com/jlong/serve

License

Serve is released under the MIT license and is copyright © 2007-2010 John W. Long and Adam I. Williams. Portions have been contributed by Robert Evans and others. A copy of the MIT license can be found in the LICENSE file.

serve's People

Contributors

aiwilliams avatar benatkin avatar chriseppstein avatar jlong avatar revans avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.