coffee-rails-source-paths 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81a307f8736a87aa8dbc0875e583ee6d69280c2c
4
+ data.tar.gz: c036fcd1b0960b4fdc4c24070ac03767aff56378
5
+ SHA512:
6
+ metadata.gz: c0e97c836681b243031a509e721c87fd8a88ae0449493f4989090733a9fe80fe063df1dbcea0ff98c5be68570d42fc670a292f2ba16c215a685f82b51647523d
7
+ data.tar.gz: 31cb0247afa64c85f1dd0db5d8382662d91a94ec32e85e9032e60d008a8e976dd73d8ec89dd76fbd93b4ec0e66bfccd5626e17f10b5af2c5751dcee6a76687df
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coffee-rails-source-maps.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mark Bates
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # DO NOT USE THIS!! I DO NOT MAINTAIN IT!
2
+
3
+ # CoffeeScript Rails Source Maps
4
+
5
+ Adds CoffeeScript source maps support, introduced in version [1.6.1](http://coffeescript.org/#changelog), to Rails. This code is based on a Gist by [naan](https://gist.github.com/naan/5096056).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'coffee-rails-source-maps'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+ $ rm -rf tmp/cache/assets
17
+
18
+ Removing `tmp/cache/assets` will cause the asset pipeline to recompile all your coffeescripts on the next page load. This will ensure all source maps are generated.
19
+
20
+ ## Usage
21
+
22
+ This gem should really only be used in development mode.
23
+
24
+ ```ruby
25
+ group :development do
26
+ gem 'coffee-rails-source-maps'
27
+ end
28
+ ```
29
+
30
+ This gem will create a folder called `assets/source_maps` in the Rails `public` directory. I would recommend adding this to your `.gitignore` file so you don't check this folder into git.
31
+
32
+ ```
33
+ public/assets/source_maps/
34
+ ```
35
+
36
+ ### Using Source Maps in Chrome
37
+
38
+ In order to use the source maps you need to use a browser that supports them. Chrome is an excellent choice.
39
+
40
+ Open the Chrome console and click on the settings tab. You'll see an option to enable source maps, make sure that is checked.
41
+
42
+ ![](http://i.imgur.com/5ndSqZV.jpg)
43
+
44
+ ### Activating the Map
45
+
46
+ Finally to see your CoffeeScript code in the Chrome console just add a `debugger` call in your code and you'll see the CoffeeScript in your console to debug.
47
+
48
+ ## Help! I'm Not Seeing Maps!
49
+
50
+ Make sure you've deleted `tmp/cache/assets`, restarted your server, enabled source maps in Chrome, and cleared its cache.
51
+
52
+ Good luck!
53
+
54
+ ## Acknowledgements
55
+
56
+ This gem is based on the following Gist: [https://gist.github.com/naan/5096056](https://gist.github.com/naan/5096056).
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
65
+
66
+ ## Contributers
67
+
68
+ * Mark Bates
69
+ * Raymond Vellener
70
+ * Sean Santry
71
+ * Eric Boehs
72
+ * Tim Moore
73
+ * Sam Dornan
74
+ * Brent Dillingham
75
+ * Alexey Chernenkov
76
+ * Curtis Steckel
77
+ * Whitney Young
78
+ * Thomas Walpole
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coffee-rails-source-maps/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "coffee-rails-source-paths"
8
+ gem.version = CoffeeRailsSourceMaps::VERSION
9
+ gem.authors = ["Damian Trojnar"]
10
+ gem.email = "trojnar.damian@gmail.com"
11
+ gem.description = %q{Adds support to Rails for CoffeeScript Source Maps}
12
+ gem.summary = %q{Adds support to Rails for CoffeeScript Source Maps}
13
+ gem.homepage = ""
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency("coffee-script-source", ">= 1.6.1")
22
+ gem.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,85 @@
1
+ require "coffee-rails-source-maps/version"
2
+
3
+ # Based on https://gist.github.com/naan/5096056
4
+ # config/initializers/source_maps.rb
5
+
6
+ if Rails.env.development?
7
+ require 'coffee-script' #make sure CoffeeScript is loaded before we overwrite it.
8
+ module CoffeeScript
9
+
10
+ class << self
11
+
12
+ def compile(script, options = {})
13
+ script = script.read if script.respond_to?(:read)
14
+
15
+ if options.key?(:no_wrap) && !options.key?(:bare)
16
+ options[:bare] = options[:no_wrap]
17
+ else
18
+ options[:bare] = false
19
+ end
20
+
21
+ pathname = options[:pathname]
22
+ if pathname.nil?
23
+ return Source.context.call("CoffeeScript.compile", script, options)
24
+ else
25
+ clean_name = pathname.basename.to_s.split(".").first
26
+
27
+ rel_path = if pathname.to_s.start_with?(Bundler.bundle_path.to_s)
28
+ Pathname('bundler').join(pathname.relative_path_from(Bundler.bundle_path)).dirname
29
+ else
30
+ pathname.relative_path_from(Rails.root).dirname
31
+ end
32
+
33
+ map_dir = Rails.root.join("public/" + Rails.configuration.assets.prefix, "source_maps", rel_path)
34
+ map_dir.mkpath
35
+
36
+ map_file = map_dir.join("#{clean_name}.map")
37
+ coffee_file = map_dir.join("#{clean_name}.coffee")
38
+
39
+ options[:sourceMap] = true
40
+ options[:filename] = "#{clean_name}.coffee" # coffee requires filename option to work with source maps (see http://coffeescript.org/documentation/docs/coffee-script.html#section-4)
41
+ options[:sourceFiles] = ["/#{coffee_file.relative_path_from(Rails.root.join("public"))}"] # specify coffee source file explicitly (see http://coffeescript.org/documentation/docs/sourcemap.html#section-8)
42
+
43
+ wrapper = <<-WRAPPER
44
+ (function(script, options) {
45
+ try {
46
+ return CoffeeScript.compile(script, options);
47
+ } catch (err) {
48
+ if (err instanceof SyntaxError && err.location) {
49
+ throw new SyntaxError([options.filename, err.location.first_line + 1, err.location.first_column + 1].join(":") + ": " + err.message)
50
+ } else {
51
+ throw err;
52
+ }
53
+ }
54
+ })
55
+ WRAPPER
56
+
57
+ ret = Source.context.call(wrapper, script, options)
58
+
59
+ coffee_file.open('w') {|f| f.puts script }
60
+ map_file.open('w') {|f| f.puts ret["v3SourceMap"]}
61
+
62
+ comment = "//# sourceMappingURL=/#{map_file.relative_path_from(Rails.root.join("public"))}\n"
63
+ # This will add file source that can be used in directives or controllers
64
+ filePath = "var sourcePath='#{options[:pathname]}'\n"
65
+ return filePath + ret['js'] + comment
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end
72
+
73
+ # Monkeypatch this method to include the scripts' pathname
74
+ require 'tilt/coffee'
75
+
76
+ module Tilt
77
+ class CoffeeScriptTemplate < Template
78
+ def evaluate(scope, locals, &block)
79
+ pathname = scope.respond_to?(:pathname) ? scope.pathname : nil
80
+ @output ||= CoffeeScript.compile(data, options.merge(:pathname => pathname))
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,3 @@
1
+ module CoffeeRailsSourceMaps
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coffee-rails-source-paths
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Damian Trojnar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coffee-script-source
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Adds support to Rails for CoffeeScript Source Maps
42
+ email: trojnar.damian@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".rspec"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - coffee-rails-source-paths.gemspec
54
+ - lib/coffee-rails-source-maps.rb
55
+ - lib/coffee-rails-source-maps/version.rb
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Adds support to Rails for CoffeeScript Source Maps
80
+ test_files: []
81
+ has_rdoc: