-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add general purpose RakeHelper class for opal gems to use
- Loading branch information
1 parent
ce96e67
commit e895410
Showing
3 changed files
with
59 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'opal' | ||
|
||
module Opal | ||
class RakeHelper | ||
include Rake::DSL if defined? Rake::DSL | ||
|
||
class << self | ||
attr_accessor :instance | ||
|
||
def install_tasks | ||
self.new.install_tasks | ||
end | ||
|
||
def expose(*names) | ||
names.each do |name| | ||
define_singleton_method(name) do |*args| | ||
instance.__send__(name, *args) | ||
end | ||
end | ||
end | ||
end | ||
|
||
expose :uglify, :gzip | ||
|
||
def initialize | ||
install_tasks | ||
|
||
RakeHelper.instance = self | ||
end | ||
|
||
def install_tasks | ||
namespace :opal do | ||
end | ||
end | ||
|
||
def uglify(str) | ||
IO.popen('uglifyjs', 'r+') do |i| | ||
i.puts str | ||
i.close_write | ||
return i.read | ||
end | ||
end | ||
|
||
def gzip(str) | ||
IO.popen('gzip -f', 'r+') do |i| | ||
i.puts str | ||
i.close_write | ||
return i.read | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters