ruby-wisp 0.1.0 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb09d11913057e974e0115457cbaf81d210642d4
4
- data.tar.gz: 452aeebd8ec60dbc42945316febf25c340ada1da
3
+ metadata.gz: 65f7ed31cf6399269dbde06e60456c18efbbabf6
4
+ data.tar.gz: 2f72e442a5e253d84d5c1503cd6ab023b978c8e6
5
5
  SHA512:
6
- metadata.gz: d0fcfd9bfd0d4a3dd1f372a2a64fc633ffc77dbb492026aaebdf011cab0acc6141cc490da27ae3d75cc368bafa608314d6d0fa533f6c6b5f266be86c7357bfb5
7
- data.tar.gz: 7dff623e9eec19f5ef08fd1057cd3010ddb33e8e8a3aa416c45c6f30fa37da4df2f365cc479fd3f6f6fd49ed141c497a83ed3e42dca8be0802069ce353c2d944
6
+ metadata.gz: 15bcdb70c5f08cb7f2df04e901473b1f36d1483be7b8bfead1605c7b554502b6266beada0eb38cb0010bb047f2d4ee92085448f1c6824d0d1feca06b3800d3be
7
+ data.tar.gz: 96e7a0251334c658d1617eff6148a44a3a79e35c31c4dcc98d03251684990d3fe7f3e646ff0085cd8663556c230389c5d4553eee21884af5ae0b16ca6da2cdac
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
7
+ - rbx-19mode
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ### 1.0.0.beta1
2
+
3
+ * Integration with Rails >= 4.0.0.beta
4
+ * Add tests
5
+ * Add travis
6
+
7
+ ### 0.1.0
8
+
9
+ Initial build, one method: `Wisp.compile 'source'`
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Ruby::Wisp
1
+ # Ruby Wisp
2
2
 
3
- TODO: Write a gem description
3
+ Ruby bridge for [Wisp](https://github.com/Gozala/wisp) compiler
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ require 'wisp'
23
+
24
+ Wisp.compile "(:foo bar)"
25
+ # => "(bar || 0)[\"foo\"]"
26
+
27
+ Wisp.compile File.new "app.wisp"
28
+ Wisp.compile File.read "app.wisp"
29
+ Wisp.compile File.open "app.wisp"
30
+ ```
22
31
 
23
32
  ## Contributing
24
33
 
data/Rakefile CHANGED
@@ -1 +1,13 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Wisp
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path "../templates", __FILE__
7
+
8
+ def copy_wisp
9
+ template "javascript.js.wisp", File.join('app/assets/javascripts', class_path, "#{file_name}.js.wisp")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ ;; Place all the behaviors and hooks related to the matching controller here.
2
+ ;; All this logic will automatically be available in application.js.
3
+ ;; You can use Wisp in this file: https://github.com/Gozala/wisp
@@ -0,0 +1,39 @@
1
+ require 'rails/engine'
2
+ require 'tilt'
3
+
4
+ module Wisp
5
+ module Rails
6
+ class Railtie < ::Rails::Railtie
7
+ config.app_generators.javascript_engine :wisp
8
+
9
+ config.before_initialize do |app|
10
+ require 'wisp'
11
+ Sprockets::Engines
12
+ Sprockets.register_engine '.wisp', Wisp::Rails::WispTemplate
13
+ end
14
+ end
15
+
16
+ class WispTemplate < Tilt::Template
17
+ self.default_mime_type = 'text/javascript'
18
+
19
+ # check to see if wisp is loaded
20
+ def self.engine_initialized?
21
+ defined? ::Wisp
22
+ end
23
+
24
+ # autoload wisp library
25
+ def initialize_engine
26
+ require_template_library 'wisp'
27
+ end
28
+
29
+ def prepare
30
+ end
31
+
32
+ # compile template data with ruby wisp compiler
33
+ def evaluate scope, locals, &block
34
+ Wisp.compile data
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module Wisp
2
+ module Rails
3
+ class TemplateHandler
4
+ def self.erb_handler
5
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
6
+ end
7
+
8
+ def self.call template
9
+ compiled_source = erb_handler.call(template)
10
+ "Wisp.compile(begin;#{compiled_source};end)"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ ActiveSupport.on_load(:action_view) do
17
+ ActionView::Template.register_template_handler :wisp, Wisp::Rails::TemplateHandler
18
+ end
data/lib/wisp/rails.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'wisp/rails/railtie'
2
+ require 'wisp/rails/template_handler'
data/lib/wisp/runtime.rb CHANGED
@@ -32,4 +32,4 @@ module Wisp
32
32
  )
33
33
  end
34
34
  end
35
- end
35
+ end
data/lib/wisp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wisp
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0.beta1"
3
3
  end
data/lib/wisp.rb CHANGED
@@ -1,23 +1,36 @@
1
1
  require 'execjs'
2
2
  require 'wisp/source'
3
3
  require 'wisp/runtime'
4
+ require 'wisp/rails' if defined? ::Rails
4
5
 
5
6
  module Wisp
6
7
  extend Runtime
7
8
 
8
9
  class << self
10
+ # compiles wisp to js. The source object can be a File,
11
+ # StringIO, String or anything that responds to :read
9
12
  def compile source, options = {}
10
13
  source = source.read if source.respond_to?(:read)
11
14
 
12
- exec 'compile', source
15
+ begin
16
+ exec 'compile', source
17
+ rescue Exception => e
18
+ raise RuntimeError, e.to_s.delete("\n")
19
+ end
13
20
  end
14
21
 
15
22
  protected
16
-
23
+ # path to wisp library, defined in ruby-wisp-source gem
17
24
  def bundled_path
18
25
  File.dirname Wisp::Source.bundled_path
19
26
  end
20
27
  end
21
28
 
22
- ENV['NODE_PATH'] = "#{File.expand_path('node_modules')}:#{File.expand_path('vendor/node_modules')}:#{bundled_path}:#{ENV['NODE_PATH']}"
29
+ # to require node packages that installed locally
30
+ ENV['NODE_PATH'] = [
31
+ File.expand_path('node_modules'),
32
+ File.expand_path('vendor/node_modules'),
33
+ bundled_path,
34
+ ENV['NODE_PATH']
35
+ ].join ':'
23
36
  end
data/ruby-wisp.gemspec CHANGED
@@ -1,19 +1,21 @@
1
1
  # encoding: utf-8
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "wisp/version"
3
+ require 'wisp/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "ruby-wisp"
6
+ s.name = 'ruby-wisp'
7
7
  s.version = Wisp::VERSION
8
- s.authors = ["Yuri Artemev"]
9
- s.email = ["i@artemeff.com"]
8
+ s.authors = ['Yuri Artemev']
9
+ s.email = ['i@artemeff.com']
10
10
  s.description = %q{Ruby Wisp is a bridge to the JS Wisp compiler}
11
11
  s.summary = %q{Ruby Wisp compiler}
12
- s.homepage = "https://github.com/artemeff/ruby-wisp"
13
- s.license = "MIT"
12
+ s.homepage = 'https://github.com/artemeff/ruby-wisp'
13
+ s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split($/)
16
16
 
17
- s.add_dependency "ruby-wisp-source"
18
- s.add_dependency "execjs"
17
+ s.add_dependency 'execjs'
18
+ s.add_dependency 'ruby-wisp-source'
19
+
20
+ s.add_development_dependency 'railties', '>= 4.0.0.beta', '< 5.0'
19
21
  end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/wisp/assets/assets_generator'
3
+
4
+ class AssetGeneratorTest < Rails::Generators::TestCase
5
+ tests Wisp::Generators::AssetsGenerator
6
+
7
+ destination File.expand_path("../tmp", __FILE__)
8
+ setup :prepare_destination
9
+
10
+ def test_assets
11
+ run_generator %w(posts)
12
+ assert_no_file "app/assets/javascripts/posts.js"
13
+ assert_file "app/assets/javascripts/posts.js.wisp"
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/rails/controller/controller_generator'
3
+ require 'rails/generators/wisp/assets/assets_generator'
4
+
5
+ class ControllerGeneratorTest < Rails::Generators::TestCase
6
+ tests Rails::Generators::ControllerGenerator
7
+
8
+ destination File.expand_path("../tmp", __FILE__)
9
+ setup do
10
+ prepare_destination
11
+ copy_routes
12
+ end
13
+
14
+ def test_assets
15
+ run_generator %w(posts --javascript-engine=wisp --orm=false)
16
+ assert_no_file "app/assets/javascripts/posts.js"
17
+ assert_file "app/assets/javascripts/posts.js.wisp"
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/rails/scaffold/scaffold_generator'
3
+ require 'rails/generators/wisp/assets/assets_generator'
4
+
5
+ class ScaffoldGeneratorTest < Rails::Generators::TestCase
6
+ tests Rails::Generators::ScaffoldGenerator
7
+
8
+ destination File.expand_path("../tmp", __FILE__)
9
+ setup do
10
+ prepare_destination
11
+ copy_routes
12
+ end
13
+
14
+ def test_assets
15
+ run_generator %w(posts --javascript-engine=wisp --orm=false)
16
+ assert_no_file "app/assets/javascripts/posts.js"
17
+ assert_file "app/assets/javascripts/posts.js.wisp"
18
+ end
19
+ end
File without changes
@@ -0,0 +1 @@
1
+ (print "hello world")
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+ require 'action_controller'
3
+ require 'wisp'
4
+
5
+ class SiteController < ActionController::Base
6
+ self.view_paths = File.expand_path("../support", __FILE__)
7
+ end
8
+
9
+ App = ActionDispatch::Routing::RouteSet.new
10
+ App.draw do
11
+ get "site/index"
12
+ end
13
+
14
+ class TemplateHandlerTest < ActiveSupport::TestCase
15
+ include Rack::Test::Methods
16
+
17
+ def app
18
+ @app ||= App
19
+ end
20
+
21
+ test "coffee views are served as javascript" do
22
+ get "/site/index.js"
23
+
24
+ assert_match 'console.log("hello world")', last_response.body
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ # configure rails envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'rails'
5
+ require "rails/test_help"
6
+
7
+ # for generators
8
+ require 'rails/generators/test_case'
9
+
10
+ def copy_routes
11
+ routes = File.expand_path "../support/routes.rb", __FILE__
12
+ destination = File.join destination_root, "config"
13
+
14
+ FileUtils.mkdir_p destination
15
+ FileUtils.cp routes, destination
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-wisp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Artemev
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2013-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: ruby-wisp-source
14
+ name: execjs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: execjs
28
+ name: ruby-wisp-source
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
@@ -38,6 +38,26 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0.beta
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: '5.0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 4.0.0.beta
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
41
61
  description: Ruby Wisp is a bridge to the JS Wisp compiler
42
62
  email:
43
63
  - i@artemeff.com
@@ -46,16 +66,30 @@ extensions: []
46
66
  extra_rdoc_files: []
47
67
  files:
48
68
  - .gitignore
69
+ - .travis.yml
70
+ - CHANGELOG.md
49
71
  - Gemfile
50
72
  - LICENSE
51
73
  - README.md
52
74
  - Rakefile
75
+ - lib/rails/generators/wisp/assets/assets_generator.rb
76
+ - lib/rails/generators/wisp/assets/templates/javascript.js.wisp
53
77
  - lib/wisp.rb
78
+ - lib/wisp/rails.rb
79
+ - lib/wisp/rails/railtie.rb
80
+ - lib/wisp/rails/template_handler.rb
54
81
  - lib/wisp/runtime.rb
55
82
  - lib/wisp/runtime/compiler.js
56
83
  - lib/wisp/runtime/runner.js
57
84
  - lib/wisp/version.rb
58
85
  - ruby-wisp.gemspec
86
+ - test/assets_generator_test.rb
87
+ - test/controller_generator_test.rb
88
+ - test/scaffold_generator_test.rb
89
+ - test/support/routes.rb
90
+ - test/support/site/index.js.wisp
91
+ - test/template_handler_test.rb
92
+ - test/test_helper.rb
59
93
  homepage: https://github.com/artemeff/ruby-wisp
60
94
  licenses:
61
95
  - MIT
@@ -71,9 +105,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
105
  version: '0'
72
106
  required_rubygems_version: !ruby/object:Gem::Requirement
73
107
  requirements:
74
- - - '>='
108
+ - - '>'
75
109
  - !ruby/object:Gem::Version
76
- version: '0'
110
+ version: 1.3.1
77
111
  requirements: []
78
112
  rubyforge_project:
79
113
  rubygems_version: 2.0.3