Skip to content

Commit

Permalink
Merge pull request #154 from jordanstephens/issue-152
Browse files Browse the repository at this point in the history
#152 - prefix generated files with comment
  • Loading branch information
bogdan committed Jun 26, 2015
2 parents c81f878 + aa79e84 commit 4aad04e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/js_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def initialize(options = {})

def generate
js = File.read(File.dirname(__FILE__) + "/routes.js")
js.gsub!("GEM_VERSION", JsRoutes::VERSION)
js.gsub!("APP_CLASS", Rails.application.class.to_s)
js.gsub!("NAMESPACE", @options[:namespace])
js.gsub!("DEFAULT_URL_OPTIONS", json(@options[:default_url_options].merge(deprecated_default_format)))
js.gsub!("PREFIX", @options[:prefix] || "")
Expand Down
5 changes: 5 additions & 0 deletions lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
File generated by js-routes GEM_VERSION
Based on Rails routes of APP_CLASS
*/

(function() {
var NodeTypes, ParameterMissing, Utils, createGlobalJsRoutesObject, defaults, root,
hasProp = {}.hasOwnProperty;
Expand Down
4 changes: 4 additions & 0 deletions lib/routes.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
File generated by js-routes GEM_VERSION
Based on Rails routes of APP_CLASS
###
# root is this
root = (exports ? this)

Expand Down
8 changes: 8 additions & 0 deletions spec/js_routes/generated_javascript_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@

describe "generated js" do
subject { JsRoutes.generate }

it "should include a comment in the header" do
app_class = "App"

is_expected.to include("File generated by js-routes #{JsRoutes::VERSION}")
is_expected.to include("Based on Rails routes of #{app_class}")
end

it "should call route function for each route" do
is_expected.to include("inboxes_path: Utils.route(")
end
Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def draw_routes
config.before(:all) do
# compile all js files begin
Dir["#{File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))}/**/*.coffee"].each do |coffee|
File.open(coffee.gsub(/\.coffee$/, ""), 'w') {|f| f.write(CoffeeScript.compile(File.read(coffee))) }
File.open(coffee.gsub(/\.coffee$/, ""), 'w') do |f|
f.write(CoffeeScript.compile(File.read(coffee)).lstrip)
end
end
# compile all js files end
draw_routes
Expand Down

0 comments on commit 4aad04e

Please sign in to comment.