GithubHelp home page GithubHelp logo

jlong / serve Goto Github PK

View Code? Open in Web Editor NEW
837.0 24.0 90.0 7.2 MB

Serve is a small Rack-based web server and rapid prototyping framework for Web applications (specifically Rails apps). Serve is meant to be a lightweight version of the Views part of the Rails MVC. This makes Serve an ideal framework for prototyping Rails applications or creating simple websites. Serve has full support for Rails-style partials and layouts.

Home Page: http://get-serve.com

License: Other

Ruby 60.47% ApacheConf 0.03% CSS 24.76% HTML 14.72% CoffeeScript 0.02%
webserver webservers ruby rails

serve's Introduction

Serve - Delicious ERB, Haml, and Sass

Serve is a small Rack-based web server that makes it easy to serve HTML, ERB, Haml, or a variety of template languages from any directory.

Serve is meant to be a lightweight version of the Views part of the Rails MVC. This makes Serve an ideal framework for prototyping Rails applications or creating simple websites. Serve has full support for Rails-style partials and layouts.

Serve is made with Rack & Tilt.

Installation

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

gem install serve -v 1.5.2

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

sudo gem install serve -v 1.5.2

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

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

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

Basic 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.

Learn more: get-serve.com/documentation/usage

Creating a Structured 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 add a bit of structure.

To create a structured Serve project in the “project” directory, type the following on the command line:

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

Learn more: get-serve.com/documentation/create

Layouts & Partials

Serve has full support for Rails-style layouts and partials.

Serve layouts are stored in “_layout.erb” or “_layout.haml” files in the same directory as the page they are rendering.

Learn more: get-serve.com/documentation/layouts

Serve partials (much like PHP includes) are rendered using the familiar render syntax:

<%= render "footer" %>

Learn more: get-serve.com/documentation/partials

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 custom helper methods there:

module ViewHelpers

  # Calculate the years for a copyright
  def copyright_years(start_year)
    end_year = Date.today.year
    if start_year == end_year
      start_year
    else
      start_year.to_s + "&#8211;" + end_year.to_s
    end
  end

end

You can then use your custom helper methods inside a view or layout:

<%= copyright_years(2010) %>

Serve also provides a number of stock helpers methods that are very similar to their Rails counter parts.

Learn more: get-serve.com/documentation/view-helpers

Exporting

To export your project, use the new “export” command:

serve export project output

Where “project” is the path to the project and “output” is the path to the directory where you would like your HTML and CSS generated.

Learn more: get-serve.com/documentation/export

“Design First” Prototyping

If you use a “Design First” methodology, you may find Serve especially useful for prototyping your applications. Create a separate “prototype” project for your application (using Serve) and copy views over into actual application when they are ready to go. This workflow allows the designer to focus on presentation and flow, while the developer can focuses on implementation. One benefit to this approach is that the designer can identify and fix a large number of design-related 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.

Website & Documentation

Detailed documentation is available on the Serve website: get-serve.com Build status: <img src=“https://secure.travis-ci.org/jlong/serve.png?branch=master” />

Mailing List

Have questions? Please don’t be ashamed to ask. Post them on the mailing list:

groups.google.com/group/serve-users

Coming up

  • We are working on a new website for serve, with a new minimal design, estimated to be released in late Augest 2015.

License

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

serve's People

Contributors

adamstac avatar aiwilliams avatar avocade avatar benatkin avatar bmaland avatar bomberstudios avatar brentkirby avatar chriseppstein avatar chrisjlee avatar eval avatar hungtatai avatar hursman avatar iamsolarpowered avatar jess avatar jessmartin avatar jlong avatar nathos avatar neomindryan avatar ntalbott avatar revans avatar seanbrant avatar sid137 avatar wazery avatar zaeleus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serve's Issues

create fails

it can't find the license template:

((52c3da6...))$ serve create
      create  mockups
      create  mockups/public
      create  mockups/tmp
      create  mockups/views
      create  mockups/config.ru
/home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/project.rb:108:in `read': No such file or directory - ../../../.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/templates/LICENSE (Errno::ENOENT)
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/project.rb:108:in `read_template'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/project.rb:67:in `setup_base'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/project.rb:22:in `create'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/application.rb:23:in `run'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/lib/serve/application.rb:11:in `run'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/gems/serve-1.0.0/bin/serve:16
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/bin/serve:19:in `load'
        from /home/gert/.rvm/gems/ree-1.8.7-2010.02@serve/bin/serve:19

Allow links to .css as well as .sass

Very cool that you allow direct links to .sass. However would be even cooler if you could link to .css files (that don't exist) and it would route directly to the .sass file at the same location (but with .scss or .sass extension instead). This should only be the case if theres not already a .css at that path.

Problems starting Serve on OSX

Great Project, I copyed the Radiant prototype to do some work on it, but having troubles starting serve:

serve
/Library/Ruby/Gems/1.8/gems/serve-0.10.0/lib/serve/file_resolver.rb:4: undefined method mattr_accessor' for Serve:Module (NoMethodError) from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/serve-0.10.0/lib/serve.rb:2 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/serve-0.10.0/bin/serve:13 from /usr/bin/serve:19:inload'
from /usr/bin/serve:19

/Library/Ruby/Gems/1.8/gems/serve-0.10.0/lib/serve/file_resolver.rb:4
= line 4 is mattr_accessor :file_resolver

Im on OSX using latest version 0.10 of serve
with ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]
Rails 2.3.5

How can I fix this issue?

undefined method `declare' for Sass::Script::Functions:Module

Started getting this error after installing edge versions for Compass/Haml/Sass.

Gem list:

compass (0.11.beta.2, 0.10.6, 0.10.5, 0.10.4, 0.10.2)
haml (3.1.0.alpha.147, 3.0.25, 3.0.23, 3.0.17, 3.0.15)
rack (1.2.1, 1.1.0, 1.0.1)
sass (3.1.0.alpha.221)
serve (1.0.0)

Moving the "require 'sass/plugin/rack'" line after the "Compass.configure_sass_plugin!" line in config.ru fixes the problem. (Figured this out with a little help from our developer. I'm a designer so I'm clueless when it comes to config.ru)

Serve create has Sass and Compass dependencies

Serve's create command generates a project example which relies on Sass and Compass. I set up a new project, installed Serve, ran serve create . and then serve and it complained that it needed Sass (then Compass later). It seems to me that either Sass and Compass should be included as dependencies of Serve, or the create command should output a little message saying "Serve has generated a basic project for you in #[directory}. Make sure you have 'compass' gem or [take whatever steps necessary to remove Compass]"

I'm not sure what is best, but /project/config.ru:16:in require': no such file to load -- sass (LoadError) doesn't make for a very nice first run experience.

Support for linking a CSS file outside the serve "Root"

Would it be possible to add a feature to add linking to a CSS file that is outside the Serve Root folder?

Example:
/home/my_site/
cd /home/my_site
serve

Then link a CSS file inside
/home/css/mycss.css

I could not make this work with several link tactics, not even inserting a file:// which seems strange. Any suggestion on this?

dependency conflicts with actionpack-3.0.9

I wanted to use some helper methods from actionpack/action_view but serve depend on newer version of these libs than rails.

Would it be possible to go down to the versions actionpack depends on?

Gem::LoadError at /
Unable to activate actionpack-3.0.9,
because rack-test-0.6.0 conflicts with rack-test (~> 0.5.7),
rack-1.3.0 conflicts with rack (~> 1.2.1),
i18n-0.6.0 conflicts with i18n (~> 0.5.0),
builder-3.0.0 conflicts with builder (~> 2.1.2)

Support for Compass plugins?

Does Serve support Compass plugins like Susy & 960.gs? I'm not sure where to require them so they can work properly.

.less parsed with an error

When I'm trying to browse my served .less file, the only thing I get is:

NoMethodError at /somefile.less
undefined method `parse' for Less:Module

The last traceback is:

/usr/local/rvm/gems/ruby-1.9.3-p125/gems/serve-1.5.1/lib/serve/handlers/less_handler.rb: in parse
Less.parse(string)

I have ruby 1.9.3 installed with less 2.1.0 and serve 1.5.1. The .less file can be of any contents, like the following:

body {
  background: red;
}

index.html files

After upgrading to v0.11, index.html files were no longer served when accessing a folder.

Acceptance test framework helpers

Perhaps I have misunderstood Serve's scope:

It seems natural to want to use the same acceptance test framework when describing your prototype, as you do for the actual end product.

Hence it would be nice to have some such option

Serve.bdd_framework = :capybara

This would ensure capybara's rspec helpers are available?

Sensible

blank is invalid

I get :

/home/lsoave/.rvm/gems/ruby-1.9.2-p136/gems/serve-1.5.0/lib/serve/project.rb:87:in `copy_project_template': invalid template (RuntimeError)

running "serve create -t blank my-project", anyway it seems to create the sructure ( have a look at http://pastie.org/2214572 )

My version is serve (1.5.0)

undefined method `add_project_configuration' for Compass:Module

$ serve create serve && cd serve && serve
~/Development/Test/serve/config.ru:16: undefined method `add_project_configuration' for Compass:Module (NoMethodError)
        from ~/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
        from ~/.rvm/gems/ruby-1.8.7-p302/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
        from ~/Development/Test/serve/config.ru:1:in `new'
        from ~/Development/Test/serve/config.ru:1
$ compass version
Compass 0.10.6

"serve export" exports layout directory

From the examples I've seen, and from the default project you get when you run "serve create project", the best practice seems to be to create a /views/layouts/default.html.erb file for the overall page layout. When you come to export the project to html, a /layouts/default.html file is also exported. Changing the file-name to _defaults.html.erb prevents this from happening, but it kind of feels like a weird and unexpected extra step to have to go to in order to create a clean export.

I think either the docs need to clarify what's going on here, or the export function should treat the /layouts/ folder as special in some way, regardless of what the files inside are named.

Add i18n as a dependency

I'm using RVM gem sets to manage my projects now and when using serve, I get this in my stack trace:

You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install

I'm assuming this is a broken dependency chain issue.

Serve+Haml renders improper closing </body>

Interesting bug.

I use serve to prototype CMS based layouts. I use a directory for each layout... so I have views/news and in there...

views/news/_layout.html.haml and views/news/index.html.haml

It all renders fine, but serve+haml always inserts a closing tag at the end of where the content in index is yielding.

Not ideal for sure.. any idea why this happens. I suppose I could only blame Haml since it is responsible for the actual content being rendered... but then again...

Anyone else seen serve render content where haml mistakenly closed of yielded content???

url throws 404

Hi --

If I try to serve the file, "/patches/profiler_support_content_types--939808#comment-3628880.patch" , I get a 404 and in the log output it appears the filename is being truncated on the hashmark (Ruby comment symbol ... ):

web:serve david$ serve
Mongrel 1.1.5 available at http://0.0.0.0:4000
127.0.0.1 - - [13/Dec/2011 08:26:41] "GET /eap_base-7.x-1.x-dev.tar.gz HTTP/1.1" 200 2534 0.0153
127.0.0.1 - - [13/Dec/2011 08:27:01] "GET /patches/profiler_support_content_types--939808 HTTP/1.1" 404 0 0

If I remove the hash mark in the URL the file serves up ok:

Mongrel 1.1.5 available at http://0.0.0.0:4000
127.0.0.1 - - [13/Dec/2011 08:26:41] "GET /eap_base-7.x-1.x-dev.tar.gz HTTP/1.1" 200 2534 0.0153
127.0.0.1 - - [13/Dec/2011 08:27:01] "GET /patches/profiler_support_content_types--939808comment-3628880.patch 
HTTP/1.1" 200 840 0.0008

I looked briefly at the source code -- but i'm in PHP land at the moment and my Ruby-fu isn't up to the task :/

More Rails helpers

What do you think about adding stylesheet_link_tag and javascript_include_tag to Serve helpers? This would help converting a project started with Serve into a Rails app.

Can't start serve on a different port

$ serve 2100
[2011-09-05 13:43:36] INFO  WEBrick 1.3.1
[2011-09-05 13:43:36] INFO  ruby 1.9.2 (2011-07-09) [x86_64-darwin11.1.0]
[2011-09-05 13:43:36] INFO  WEBrick::HTTPServer#start: pid=40613 port=4000

It's running on port 4000, I'd expect it to use port 2100.

export slim template to static html

I just found out that when the project is done with SLIM, Serve doesn't output the static html files like it does with HAML.

Very sad panda :(
will have to convert everything ....

Parent layout

When I use the latest released version of the gem, it works in that it picks up a layout that's in a parent directory.

When I use what's currently in master, my parent layout isn't picked up.

Export files to html

I was thinking of what could be great addition to serve,

adding an option to the command line like:
serve --export
adding
output_dir = /html to config file

Then if run seve --export it will render all haml files to html files inside the output_dir

I found a snippet of code to write the haml to html

http://gist.github.com/17371

Any ideas on this?
Currently I copy and paste the html from the browser, is there a better way?
( I do design in haml but need the html output for cms implementation )

serve export overwrites html files without warning

I had a Compass project that I converted into a Serve project. This procedure left an index.html file inside the public folder.

When I start serve export it seems like it first renders everything to the target folder and then copies the public folder into target overwriting existing files inside the target folder.

I think there are several methods how to deal with this.

  1. the most simple approach would be to change the order of these two tasks
  2. there should be a warning whenever an existing file is overwritten
  3. there should be an interactive query for the user: "Overwrite? [Yn]"

I guess there are several other methods more for handling this problem. I would vote for 1 and could provide a patch if needed. Please tell me what you think.

Serve not exporting the right DOCTYPE

@JakeCarter in #22:

Serve is now outputting my Haml as HTML5 when using the Serve server. But when I do a serve export, its still outputting XHTML 1.0 Transitional. Is there a work around for this?

Also:

Ok, I created a test project here: https://github.com/JakeCarter/html5test

When I use serve to serve the project it will render them as HTML5, but when I use serve export it will render them as XHTML 1.0 Transitional.

Slim view helpers and layouts

Thanks for the work on serve, it is helping us prototype apps.

We are using Slim templates and seem to be having some problems.

The default view helpers don't seem to work, it appears the helpers are parsed before slim is parsed so slim interrupts them and adds quotes around the tags.

If we have a layout that is in slim and yield to a slim file it won't compile the yielded file correctly. If the layout is in erb and we yield to a slim file it works though.

Any ideas?

thanks,
gustin

POST params not set?

I have this form on a view:

<form action="" method="get" accept-charset="utf-8">
  <input type="text" name="email" value="" id="email" />
  <p><input type="submit" value="Continue &rarr;" /></p>
</form>

When I submit it, I can access the email field's value with

<%= params[:email] %>

However, if I change the form method to POST, params[:email] is empty.

Any idea where to look at?

Thanks in advance...

Haml Partials?

Trying to load partials implicitly with .html.haml extension result in Serve not finding them

# partial is in shared/_header.html.haml
render :partial => "shared/header"

However when I give the full path, it works

render :partial => "shared/header.html.haml"

Possible to fix?

Haml config

Hi!

How i can set Haml options for render templates?

Inconsistent Markdown rendering in "serve export"

Per lists in Markdown, list items with blank lines between them should render as <li><p>content</p></li>. I am doing this inside nested lists:

*   *    content

    *    more content

This works fine when I run "serve" on the command line, but "serve export" generates a separate <ul> around each list item and no paragraphs. Any ideas? Thanks!

Textile partials aren't handled correctly.

<%= render "partial.html.textile" %>

throws

RuntimeError at /helpers/render/
File does not exist "/Users/rmetzler/Code/serve/test_project/helpers/render/_partial.html.textile.html.erb"

I will send you the broken Testcase.

git dependency makes installation on Windows harder than necessary

While creating a new project on Windows, we had just installed Ruby and the serve gem but not git. (Its not mentioned as a dependency) Creating a project fails in Serve::Project.git_config because there's no "git" in the path. Creating a dummy git.bat somewhere in the path helped, which simply returned a blank line. But that shouldn't be the way... :-)

"/layouts" Copied via Export

If I run...

serve export ../folder

Everything is exported to folder as expected, but the "/layouts" directory is copied over as well.

Not a big deal, but it's also not necessary, since the respective layouts are compiled down into HTML files.

Ruby 1.9.1 issues

With ruby 1.9 I cannot longer use Serve, any ideas?

config.ru:14:in block in <main>': undefined methoddirname' for Rack::File:Class (NoMethodError)
from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:in instance_eval' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:46:ininitialize'
from /Users/pascal/Desktop/Actus/concepts/sites/actus/config.ru:1:in new' from /Users/pascal/Desktop/Actus/concepts/sites/actus/config.ru:1:in

'
from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:in eval' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/builder.rb:35:inparse_file'
from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:162:in app' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:248:inwrapped_app'
from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:213:in start' from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib/rack/server.rb:100:instart'
from /usr/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin/rackup:4:in <top (required)>' from /usr/local/bin/rackup:19:inload'
from /usr/local/bin/rackup:19:in `'

I found this mention http://github.com/documentcloud/cloud-crowd/issues/issue/6
not sure how that/if it relates im not that into rack gem

Compass

Hi, I couldn't use compass in new created project. Adding "@import "compass"; " in screen.css, show me that error in console: GET http://0.0.0.0:4000/stylesheets/compass 404 (Not Found) :S.

I thank that compass was installed by defaut and there is no config to do to use it, isn't it ?

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.