SingleFile lets you build and serve beautiful, fast web apps from a single file.
Add a route
get '/' do
erb 'home'
end
Start the server
ruby singlefile.rb
What you need to build beautiful, fast web apps:
What you don't need to build beautiful, fast web apps
We've taken some liberties with our definition. What we're aiming for is:
Make It Yours
favicon.ico in the /assets/icons folder/helpers.rbstyles.css--ui-font-family:
--ui-font-family-headings:
Add a new route
Create a new file at /views/home.erb then add a route for it.
get '/' do
erb 'home'
end
Add A Link
<a href="/about">About</a>
Include a partial
<%= erb :"partials/_sidebar" %>
Styling With Tailwind
Use any of the 50,000+ Tailwind classes available through Litewind. We recommend using Tailwind primarily for layout.
<div class="flex justify-center">
</div>
Styling Forms
Add .ui-form to any form to make all of the input elements inside of it look beautiful and consistent.
<form class="ui-form"></form>
Styling Prose
Wrap the .ui-styled-text class around any html designed to render articles, markdown, or prose.
<div class="ui-styled-text">
<%= markdown_file_to_html("readme.md") %>
</div>
Buttons
Add the .ui-button class to any <button> or <a> element. (Read More about Base Styles buttons)
<button class="ui-button">Do Stuff</button>
Boxes
Use the .ui-box class to create a section of elevated content. (Read More about Base Styles boxes).
<div class="ui-box"></div>
Titles
Add the .ui-title class to any title, or create a .ui-titlepair for a title with a tagline.
<h3 class="ui-title">Coffee</h3>
<div class="ui-titlepair">
<h3 class="--title ">Coffee</h3>
<p class="--description">Size: Xl</p>
</div>
Chips
Display a list of tags using the .ui-chip class. (Read More about Base Styles chips).
<div class="ui-chip">Default</div>
Tooltips
Add an aria-label to an element alongside the .ui-tooltip class to get clean animated plain text tooltips.
<a href="#" class="ui-tooltip--top" aria-label="Use the ui-tooltip--top class">
Tooltip Top
</a>
Dropdowns
Use popover elements wrapped in a .ui-dropdown to create customizable, styled dropdowns. (Read More about Base Styles Dropdowns).
<div class="ui-dropdown">
<button class="--trigger" popovertarget="dropdown-content">
Click To Open
</button>
<div class="--drawer --bottom p-1 " id="dropdown-content" popover>
<a class="ui-button --minimal">
Google.com
</a>
</div>
</div>
Modals
Use commandfor and add the .ui-modal class to your dialog element. (Read More about Base Styles modals).
<button commandfor="confirm-dialog" command="show-dialog">
Delete Record
</button>
<dialog class="ui-modal" id="confirm-dialog" closedby="any" >
<p>Are you sure? This action cannot be undone</p>
<button class="ui-button">Continue</button>
</dialog>
Make an element dynamic, define some simple state, and render the value
<ui-state message="Hello World!">
<div ui-text="message"></div>
</ui-state>
Use javascript to update state from user interaction
<ui-state count="0">
<button ui-click="count++">Increment</button>
<div ui-text="count"></div>
</ui-state>
React to changes in input values
Use this.value to get the current value of the form input, and ui-change to listen for changes.
<ui-state name="">
<input type="text" ui-change="name = this.value" />
<span ui-text="name"></span>
</ui-state>
More Useful Info
first-name becomes firstName)Render dynamic content inside your html
Use the <%= %> syntax inside your html files (Read More about Embedded Ruby).
<%= Time.now %>
Forms
<form action="">
</form>
Helpers
Use any of ActiveSupport's 100+ methods. (Read More about ActiveSupport).
<%= 'dublin'.capitalize %>
bundle installruby singlefile.rbIsn't this just Sinatra?
Sort of, yes. The codebase uses Sinatra, which is designed to be a single file framework. We use it as a shell to provide some simple patterns (routing, templating) and act as glue to bring together several other frameworks that we've built. If you'd like to port this to your language of choice, we'd love to feature you.
How did you decide on what libraries to include?
We've spent a lot of time thinking about patterns for working effectively with HTML, in a way that goes with the grain of the web, and isn't tighly coupled to any particular framework. Base Styles was built to solve our own problems internally (effortless style and consistency), and Mini Js was similar. Both have been refined in production for 3 years across dozens of projects and codebases. We've evolved our approach and syntax over time and landed somewhere that we think is a good balance between simplicity and power.