- Notifications
You must be signed in to change notification settings - Fork17
opal/opal-sprockets
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Adds sprockets support forOpal.
Add to yourGemfile:
gem"opal-sprockets"
The version number is an attempt to keep track and support different combinations of both opal and sprockets without cluttering the code with giantifs and conditional requires. The structure is roughly as follows:
<basic version number>.<opal version number>.<sprockets version numbers>
For example version0.4.1.0.11.0.rc1.3.1 is build taking into account the following components:
BASE_VERSION = '0.4.1'OPAL_VERSION = '0.11.0.rc1'SPROCKETS_VERSION = '3.1'Sprockets uses a set of load paths to resolve dependencies. This gem extendssprockets to provide opal load paths to sprockets.opal-sprockets providesa template processor for all files with.rb or.opal extensions.
#= require opalputs"opal running in sprockets!"
By default, sprockets will examine your code for processor directive commentsto handle requires, e.g.#= require opal. Opal takes this one step futherby extending the opal processor to automatically detect and register anyrequire call made inside your ruby code:
require"opal"require"opal-jquery"puts"opal-jquery is now available!"
Opal cannot require files at runtime, so this trick allows ruby code to usethe nicer ruby syntax for requiring dependencies.
Sprockets uses a load path for code files, so make a simpleapp/ directorywith some code insideapp/application.rb:
# app/application.rbrequire"opal"puts"hello, world"
The opal corelib and runtime can be included in your app simply by addingrequire "opal". We also need an html file to test the application with,so addindex.html:
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><scriptsrc="/assets/application.js"></script></head><body></body></html>
opal-sprockets comes with a simpleServer class that can be used to easilyconfigure applications insideconfig.ru:
# config.rurequire'bundler'Bundler.requirerunOpal::Sprockets::Server.new{ |s|s.append_path'app's.main='application'# This can be used to provide a custom index file.# s.index_path = 'my_index.erb'}
This just adds theapp/ directory to the load path, and tells sprockets thatapplication.rb will be the main file to load.
Now just run the rack app:
$ bundle exec rackupAnd then visithttp://127.0.0.1:9292 in any browser.
opal-sprockets will create source maps for all assets by default. You can disable this with:
Opal::Config.source_map_enabled=false
(The MIT License)
Copyright (C) 2013 by Adam BeynonCopyright (C) 2013 by Elia Schito
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.
About
Sprockets support for Opal (used to be embedded into Opal from v0.6 up to v0.10)
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.