Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sprockets support for Opal (used to be embedded into Opal from v0.6 up to v0.10)

NotificationsYou must be signed in to change notification settings

opal/opal-sprockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

136 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Adds sprockets support forOpal.

Installation

Add to yourGemfile:

gem"opal-sprockets"

A note on the version number

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'

Usage

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!"

Improved require support

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.

Example

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>

Running Application

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 rackup

And then visithttp://127.0.0.1:9292 in any browser.

Source Maps

opal-sprockets will create source maps for all assets by default. You can disable this with:

Opal::Config.source_map_enabled=false

License

(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

Stars

Watchers

Forks

Packages

No packages published

Contributors10

Languages


[8]ページ先頭

©2009-2026 Movatter.jp