Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Make minor cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
carsomyr committed Sep 22, 2014
1 parent 913f599 commit dd10bdb
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 109 deletions.
2 changes: 1 addition & 1 deletion lib/requirejs-rails.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require 'requirejs/rails'
require "requirejs/rails"
2 changes: 1 addition & 1 deletion lib/requirejs/rails.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Requirejs
module Rails
require 'requirejs/rails/engine'
require "requirejs/rails/engine"
end
end
48 changes: 24 additions & 24 deletions lib/requirejs/rails/builder.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
require 'requirejs/rails'
require "ostruct"
require "pathname"

require 'pathname'
require 'ostruct'
require "requirejs/rails"

module Requirejs::Rails
class Builder
# config should be an instance of Requirejs::Rails::Config

def initialize(config)
@config = config
end

def build
@config.tmp_dir
end
module Requirejs
module Rails
class Builder
def initialize(config)
@config = config
end

def digest_for(path)
if !Rails.application.assets.file_digest(path).nil?
Rails.application.assets.file_digest(path).hexdigest
else
raise Requirejs::BuildError, "Cannot compute digest for missing asset: #{path}"
def build
@config.tmp_dir
end

def digest_for(path)
if !::Rails.application.assets.file_digest(path).nil?
::Rails.application.assets.file_digest(path).hexdigest
else
raise Requirejs::BuildError, "Cannot compute digest for missing asset: #{path}"
end
end
end

def generate_rjs_driver
templ = Erubis::Eruby.new(@config.driver_template_path.read)
@config.driver_path.open('w') do |f|
f.write(templ.result(@config.get_binding))
def generate_rjs_driver
templ = Erubis::Eruby.new(@config.driver_template_path.read)
@config.driver_path.open('w') do |f|
f.write(templ.result(@config.get_binding))
end
end
end
end
Expand Down
149 changes: 76 additions & 73 deletions lib/requirejs/rails/config.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
require 'requirejs/rails'
require 'requirejs/error'
require "pathname"

require 'active_support/ordered_options'
require 'erubis'
require 'pathname'
require "active_support/ordered_options"
require "erubis"

module Requirejs::Rails
class Config < ::ActiveSupport::OrderedOptions
LOADERS = [ :requirejs, :almond ]
require "requirejs/error"
require "requirejs/rails"

def initialize(application)
super
self.manifest = nil
module Requirejs
module Rails
class Config < ::ActiveSupport::OrderedOptions
LOADERS = [:requirejs, :almond]

self.logical_asset_filter = [/\.js$/,/\.html$/,/\.txt$/]
self.tmp_dir = application.root + 'tmp'
self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath
def initialize(application)
super
self.manifest = nil

self.source_dir = self.tmp_dir.join("requirejs/src")
self.build_dir = self.tmp_dir.join("requirejs/dst")
self.target_dir = application.root + 'public/assets'
self.rjs_path = self.bin_dir+'r.js'
self.logical_asset_filter = [/\.js$/, /\.html$/, /\.txt$/]
self.tmp_dir = application.root + 'tmp'
self.bin_dir = Pathname.new(__FILE__+'/../../../../bin').cleanpath

self.loader = :requirejs
self.source_dir = self.tmp_dir.join("requirejs/src")
self.build_dir = self.tmp_dir.join("requirejs/dst")
self.target_dir = application.root + 'public/assets'
self.rjs_path = self.bin_dir+'r.js'

self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
self.driver_path = self.tmp_dir.join("requirejs/rjs_driver.js")
self.loader = :requirejs

self.user_config = {}
self.driver_template_path = Pathname.new(__FILE__+'/../rjs_driver.js.erb').cleanpath
self.driver_path = self.tmp_dir.join("requirejs/rjs_driver.js")

self.run_config_whitelist = %w{
self.user_config = {}

self.run_config_whitelist = %w{
baseUrl
callback
catchError
Expand All @@ -49,7 +51,7 @@ def initialize(application)
xhtml
}

self.build_config_whitelist = %w{
self.build_config_whitelist = %w{
appDir
baseUrl
closure
Expand Down Expand Up @@ -88,69 +90,70 @@ def initialize(application)
useStrict
wrap
}
end
end

def loader=(sym)
unless LOADERS.include?(sym)
raise Requirejs::ConfigError, "Attempt to set unknown loader: #{sym}"
def loader=(sym)
unless LOADERS.include?(sym)
raise Requirejs::ConfigError, "Attempt to set unknown loader: #{sym}"
end
self[:loader] = sym
end
self[:loader] = sym
end

def build_config
unless self.has_key?(:build_config)
self[:build_config] = self.run_config.merge "baseUrl" => source_dir.to_s,
"modules" => [ { 'name' => 'application' } ]
self[:build_config].merge!(self.user_config).slice!(*self.build_config_whitelist)
case self.loader
when :requirejs
# nothing to do
when :almond
mods = self[:build_config]['modules']
unless mods.length == 1
raise Requirejs::ConfigError, "Almond build requires exactly one module, config has #{mods.length}."
def build_config
unless self.has_key?(:build_config)
self[:build_config] = self.run_config.merge "baseUrl" => source_dir.to_s,
"modules" => [{'name' => 'application'}]
self[:build_config].merge!(self.user_config).slice!(*self.build_config_whitelist)
case self.loader
when :requirejs
# nothing to do
when :almond
mods = self[:build_config]['modules']
unless mods.length == 1
raise Requirejs::ConfigError, "Almond build requires exactly one module, config has #{mods.length}."
end
mod = mods[0]
name = mod['name']
mod['name'] = 'almond'
mod['include'] = name
end
mod = mods[0]
name = mod['name']
mod['name'] = 'almond'
mod['include'] = name
end
self[:build_config]
end
self[:build_config]
end

def run_config
unless self.has_key?(:run_config)
self[:run_config] = { "baseUrl" => "/assets" }
self[:run_config].merge!(self.user_config).slice!(*self.run_config_whitelist)
def run_config
unless self.has_key?(:run_config)
self[:run_config] = {"baseUrl" => "/assets"}
self[:run_config].merge!(self.user_config).slice!(*self.run_config_whitelist)
end
self[:run_config]
end
self[:run_config]
end

def user_config=(cfg)
if url = cfg.delete('baseUrl')
raise Requirejs::ConfigError, "baseUrl is not needed or permitted in the configuration"
def user_config=(cfg)
if url = cfg.delete('baseUrl')
raise Requirejs::ConfigError, "baseUrl is not needed or permitted in the configuration"
end
self[:user_config] = cfg
end
self[:user_config] = cfg
end

def module_name_for(mod)
case self.loader
when :almond
return mod['include']
when :requirejs
return mod['name']
def module_name_for(mod)
case self.loader
when :almond
return mod['include']
when :requirejs
return mod['name']
end
end
end

def get_binding
return binding()
end
def get_binding
return binding()
end

def asset_allowed?(asset)
self.logical_asset_filter.reduce(false) do |accum, matcher|
accum || (matcher =~ asset)
end ? true : false
def asset_allowed?(asset)
self.logical_asset_filter.reduce(false) do |accum, matcher|
accum || (matcher =~ asset)
end ? true : false
end
end
end
end
4 changes: 2 additions & 2 deletions lib/requirejs/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'requirejs/rails/config'
require "pathname"

require 'pathname'
require "requirejs/rails/config"

module Requirejs
module Rails
Expand Down
15 changes: 7 additions & 8 deletions lib/tasks/requirejs-rails_tasks.rake
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'requirejs/rails/builder'
require 'requirejs/rails/config'
require "fileutils"
require "pathname"
require "tempfile"

require 'fileutils'
require 'pathname'
require "active_support/ordered_options"
require "sprockets"

require 'sprockets'
require 'tempfile'

require 'active_support/ordered_options'
require "requirejs/rails/builder"
require "requirejs/rails/config"

namespace :requirejs do
# This method was backported from an earlier version of Sprockets.
Expand Down

0 comments on commit dd10bdb

Please sign in to comment.