jekyll-opal 0.0.1 → 0.1.0

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: 0a2e4c04c59f9edfed2577093fed6a82ed3fb596
4
- data.tar.gz: 57e248e6e11022ed7a612f6aaf0c201ca1b79a56
3
+ metadata.gz: 572cf221b7ea9c111c2db90cb06d7c6faf375f8f
4
+ data.tar.gz: 889c457a57b43aff2c70501124275a31cb7d3306
5
5
  SHA512:
6
- metadata.gz: c5a71e4e69cdf2163e2ca15912110ccde8983b1bbe8b0f56077c504583ee37316dd33964f673fe72be308a8c277b9874c8516f82b091b45cc446f36927f0473c
7
- data.tar.gz: e3e72d5f1b23f03757954929b3b33fbc651f3e9de596702fa1cb77e96df2a3051253bb6e50ed9667ff44b9401a40a59532a6d50b380cb8b906334a29394130d3
6
+ metadata.gz: 1050c10ce1edadba8fe2eb0a92985ad3bb3d117e8b9c65ef7f4941ac7c319d0ecd2a8f0992081e597425458d7986263012198590d96080d8ce254c854283c71e
7
+ data.tar.gz: ed6a41d8c3e2f45a48e17c20b12687e8595e2a8fae1697898ab3a04b906f1ee8327b99e028b213ac4906c9f9c9010b77535f42805625c793b421aa760d597bc4
data/.gitignore CHANGED
@@ -12,6 +12,7 @@ lib/bundler/man
12
12
  pkg
13
13
  rdoc
14
14
  spec/reports
15
+ spec/dest
15
16
  test/tmp
16
17
  test/version_tmp
17
18
  tmp
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ script : script/cibuild
3
+ rvm:
4
+ - 2.1
5
+ - 2.0
6
+ - 1.9.3
7
+ notifications:
8
+ email: false
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in jekyll-opal.gemspec
4
2
  gemspec
@@ -0,0 +1,9 @@
1
+ ## HEAD
2
+
3
+ ### Minor Enhancements
4
+
5
+ ### Bug Fixes
6
+
7
+ ## 0.1.0 / 2014-06-16
8
+
9
+ * Birthday!
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Jekyll::Opal
1
+ # Jekyll-Opal
2
2
 
3
- TODO: Write a gem description
3
+ Let Jekyll convert your Ruby into JavaScript using [Opal](https://github.com/opal/opal).
4
+
5
+ [![Build Status](https://travis-ci.org/jekyll/jekyll-opal.svg?branch=master)](https://travis-ci.org/jekyll/jekyll-opal)
4
6
 
5
7
  ## Installation
6
8
 
@@ -18,11 +20,33 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ Write your Opal in `.opal` files (be sure to add the two `---` lines at the
24
+ top to make them pages!!)
25
+
26
+ This plugin comes with a generator which creates the Opal library file in
27
+ the destination, under `js/opal.js`, if it's not already there. To prevent
28
+ backwards-incompatible sites, we ship a `{{ site.opal.url }}` variable for
29
+ your use in your sites. When output, it will look like this: `/js/opal.js`.
30
+
31
+ If your site is served in a subfolder (i.e. `http://example.org/subfolder/`), simply prepend a baseurl:
32
+
33
+ ```html
34
+ <script src="{{ site.opal.url | prepend:"my_subfolder" }}"></script>
35
+ ```
36
+
37
+ You can even prepend variables! Perhaps a URL?
38
+
39
+ ```html
40
+ <script src="{{ site.opal.url | prepend:"my_subfolder" | prepend:site.url }}"></script>
41
+ ```
42
+
43
+ Feel free to chain them like that -- they're just Liquid filters.
44
+
45
+ File an issue if something isn't clear!
22
46
 
23
47
  ## Contributing
24
48
 
25
- 1. Fork it ( https://github.com/[my-github-username]/jekyll-opal/fork )
49
+ 1. Fork it ( https://github.com/jekyll/jekyll-opal/fork )
26
50
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
51
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
52
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,14 +1,14 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'jekyll/opal/version'
4
+ require 'jekyll-opal/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "jekyll-opal"
8
8
  spec.version = Jekyll::Opal::VERSION
9
9
  spec.authors = ["Parker Moore"]
10
10
  spec.email = ["parkrmoore@gmail.com"]
11
- spec.summary = %q{Convert your Ruby into JavaScript using Opal.}
11
+ spec.summary = %q{Let Jekyll convert your Ruby into JavaScript using Opal.}
12
12
  spec.homepage = "https://github.com/jekyll/jekyll-opal"
13
13
  spec.license = "MIT"
14
14
 
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler", "~> 1.6"
23
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "jekyll", "~> 2.0"
24
26
  end
@@ -0,0 +1,9 @@
1
+ require "jekyll-opal/version"
2
+ require "jekyll/converters/opal"
3
+ require "jekyll/generators/opal"
4
+
5
+ module Jekyll
6
+ module Opal
7
+ OPAL_LIB_LOCATION = File.join("js", "opal.js").freeze
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Opal
3
- VERSION = "0.0.1"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,21 @@
1
+ require 'opal'
2
+
3
+ module Jekyll
4
+ module Converters
5
+ class Opal < Converter
6
+
7
+ def matches(ext)
8
+ !!(ext =~ /\.opal/i)
9
+ end
10
+
11
+ def output_ext(ext)
12
+ ".js"
13
+ end
14
+
15
+ def convert(content)
16
+ ::Opal.compile(content)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,56 @@
1
+ require 'opal'
2
+
3
+ module Jekyll
4
+ module Generators
5
+ class Opal < Generator
6
+
7
+ def generate(site)
8
+ write_file(output_location(site)) unless File.file?(output_location(site))
9
+ keep_the_file(site)
10
+ save_lib_file_location_to_config(site)
11
+ end
12
+
13
+ def write_file(location)
14
+ ensure_directory(location)
15
+ File.open(location, 'wb') do |f|
16
+ f.puts(opal_stdlib)
17
+ end
18
+ location
19
+ end
20
+
21
+ def opal_stdlib
22
+ ::Opal::Builder.build('opal')
23
+ end
24
+
25
+ def ensure_directory(location)
26
+ dir = File.dirname(location)
27
+ unless File.directory?(dir)
28
+ require 'fileutils'
29
+ FileUtils.mkdir_p(dir)
30
+ end
31
+ end
32
+
33
+ def output_location(site)
34
+ File.expand_path(opal_lib_relative_path, site.dest)
35
+ end
36
+
37
+ def keep_the_file(site)
38
+ (site.keep_files ||= []) << opal_lib_relative_path
39
+ end
40
+
41
+ def save_lib_file_location_to_config(site)
42
+ site.config["opal"] = {
43
+ "version" => ::Opal::VERSION,
44
+
45
+ # must start with a forward slash!
46
+ "url" => File.join("", opal_lib_relative_path)
47
+ }
48
+ end
49
+
50
+ def opal_lib_relative_path
51
+ Jekyll::Opal::OPAL_LIB_LOCATION
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env bash
2
+
3
+ bundle install
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rspec --color --require spec_helper
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe(Jekyll::Converters::Opal) do
4
+ let(:bogus_opal) { "hi.there( oatmeal" }
5
+ let(:simple_opal) { "puts 'ohai jekyll'" }
6
+ let(:simple_js_output) do
7
+ <<-JS
8
+ /* Generated by Opal 0.6.2 */
9
+ (function($opal) {
10
+ var self = $opal.top, $scope = $opal, nil = $opal.nil, $breaker = $opal.breaker, $slice = $opal.slice;
11
+
12
+ $opal.add_stubs(['$puts']);
13
+ return self.$puts("ohai jekyll")
14
+ })(Opal);
15
+ JS
16
+ end
17
+
18
+ it "matches .opal files" do
19
+ expect(subject.matches(".opal")).to be_truthy
20
+ end
21
+
22
+ it "outputs .js" do
23
+ expect(subject.output_ext("ANYTHING AT ALL")).to eql(".js")
24
+ end
25
+
26
+ it "converts Ruby into Opal" do
27
+ expect(subject.convert(simple_opal)).to eql(simple_js_output)
28
+ end
29
+
30
+ it "explodes on bad input" do
31
+ expect(->{ subject.convert(bogus_opal) }).to raise_error
32
+ end
33
+
34
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe(Jekyll::Generators::Opal) do
4
+ let(:output_dir) { dest_dir("js") }
5
+ let(:output_file) { dest_dir("js", "opal.js") }
6
+ let(:site) { fixture_site }
7
+
8
+ it "knows where to output the file" do
9
+ expect(subject.output_location(site)).to eql(output_file)
10
+ end
11
+
12
+ it "can build the opal stdlib" do
13
+ expect(subject.opal_stdlib).to match("(Opal);")
14
+ end
15
+
16
+ context "when ensuring directory is there" do
17
+ before(:each) do
18
+ FileUtils.rm_r(output_dir) if File.directory?(output_dir)
19
+ subject.ensure_directory(subject.output_location(site))
20
+ end
21
+
22
+ it "creates the proper output directory" do
23
+ expect(File.directory?(output_dir)).to be_truthy
24
+ end
25
+ end
26
+
27
+ context "for a fresh site" do
28
+ before(:each) do
29
+ FileUtils.rm_r(dest_dir) if File.directory?(dest_dir)
30
+ end
31
+
32
+ it "writes the file" do
33
+ expect(subject.write_file(subject.output_location(site))).to eql(output_file)
34
+ expect(File.file?(output_file)).to be(true)
35
+ end
36
+ end
37
+
38
+ it "adds the outputted file to the site.keep_files list" do
39
+ expect(subject.keep_the_file(site)).to include("js/opal.js")
40
+ expect(site.keep_files).to eql(%w(.git .svn js/opal.js))
41
+ end
42
+
43
+ it "adds the 'opal' namespace for liquid" do
44
+ expect(subject.save_lib_file_location_to_config(site)).to eql({
45
+ "version" => Opal::VERSION, "url" => "/js/opal.js"
46
+ })
47
+ expect(site.config.has_key?("opal")).to be_truthy
48
+ end
49
+
50
+ end
@@ -0,0 +1,92 @@
1
+ require 'fileutils'
2
+ require 'jekyll'
3
+
4
+ TEST_DIR = File.dirname(__FILE__)
5
+ PROJECT_DIR = File.dirname(TEST_DIR)
6
+ FIXTURE_DIR = File.expand_path("fixtures", TEST_DIR)
7
+ require File.expand_path("lib/jekyll-opal.rb", PROJECT_DIR)
8
+
9
+ RSpec.configure do |config|
10
+ # These two settings work together to allow you to limit a spec run
11
+ # to individual examples or groups you care about by tagging them with
12
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
13
+ # get run.
14
+ config.filter_run :focus
15
+ config.run_all_when_everything_filtered = true
16
+
17
+ # Many RSpec users commonly either run the entire suite or an individual
18
+ # file, and it's useful to allow more verbose output when running an
19
+ # individual spec file.
20
+ if config.files_to_run.one?
21
+ # Use the documentation formatter for detailed output,
22
+ # unless a formatter has already been configured
23
+ # (e.g. via a command-line flag).
24
+ config.default_formatter = 'doc'
25
+ end
26
+
27
+ # Print the 10 slowest examples and example groups at the
28
+ # end of the spec run, to help surface which specs are running
29
+ # particularly slow.
30
+ config.profile_examples = 3
31
+
32
+ # Run specs in random order to surface order dependencies. If you find an
33
+ # order dependency and want to debug it, you can fix the order by providing
34
+ # the seed, which is printed after each run.
35
+ # --seed 1234
36
+ config.order = :random
37
+
38
+ # Seed global randomization in this process using the `--seed` CLI option.
39
+ # Setting this allows you to use `--seed` to deterministically reproduce
40
+ # test failures related to randomization by passing the same `--seed` value
41
+ # as the one that triggered the failure.
42
+ Kernel.srand config.seed
43
+
44
+ # rspec-expectations config goes here. You can use an alternate
45
+ # assertion/expectation library such as wrong or the stdlib/minitest
46
+ # assertions if you prefer.
47
+ config.expect_with :rspec do |expectations|
48
+ # Enable only the newer, non-monkey-patching expect syntax.
49
+ # For more details, see:
50
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
51
+ expectations.syntax = :expect
52
+ end
53
+
54
+ # rspec-mocks config goes here. You can use an alternate test double
55
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
56
+ config.mock_with :rspec do |mocks|
57
+ # Enable only the newer, non-monkey-patching expect syntax.
58
+ # For more details, see:
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ mocks.syntax = :expect
61
+
62
+ # Prevents you from mocking or stubbing a method that does not exist on
63
+ # a real object. This is generally recommended.
64
+ mocks.verify_partial_doubles = true
65
+ end
66
+
67
+ def jekyll_conf(overrides = {})
68
+ Jekyll::Utils.deep_merge_hashes(
69
+ Jekyll::Configuration::DEFAULTS,
70
+ overrides
71
+ )
72
+ end
73
+
74
+ def fixture_site
75
+ Jekyll::Site.new jekyll_conf({
76
+ "source" => source_dir,
77
+ "destination" => dest_dir
78
+ })
79
+ end
80
+
81
+ def source_dir(*files)
82
+ test_dir("source", *files)
83
+ end
84
+
85
+ def dest_dir(*files)
86
+ test_dir("dest", *files)
87
+ end
88
+
89
+ def test_dir(*files)
90
+ File.join(TEST_DIR, *files)
91
+ end
92
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-opal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Parker Moore
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jekyll
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
55
83
  description:
56
84
  email:
57
85
  - parkrmoore@gmail.com
@@ -60,13 +88,22 @@ extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - ".gitignore"
91
+ - ".travis.yml"
63
92
  - Gemfile
93
+ - History.markdown
64
94
  - LICENSE.txt
65
95
  - README.md
66
96
  - Rakefile
67
97
  - jekyll-opal.gemspec
68
- - lib/jekyll/opal.rb
69
- - lib/jekyll/opal/version.rb
98
+ - lib/jekyll-opal.rb
99
+ - lib/jekyll-opal/version.rb
100
+ - lib/jekyll/converters/opal.rb
101
+ - lib/jekyll/generators/opal.rb
102
+ - script/bootstrap
103
+ - script/cibuild
104
+ - spec/opal_converter_spec.rb
105
+ - spec/opal_generator_spec.rb
106
+ - spec/spec_helper.rb
70
107
  homepage: https://github.com/jekyll/jekyll-opal
71
108
  licenses:
72
109
  - MIT
@@ -90,5 +127,8 @@ rubyforge_project:
90
127
  rubygems_version: 2.2.2
91
128
  signing_key:
92
129
  specification_version: 4
93
- summary: Convert your Ruby into JavaScript using Opal.
94
- test_files: []
130
+ summary: Let Jekyll convert your Ruby into JavaScript using Opal.
131
+ test_files:
132
+ - spec/opal_converter_spec.rb
133
+ - spec/opal_generator_spec.rb
134
+ - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- require "jekyll/opal/version"
2
-
3
- module Jekyll
4
- module Opal
5
- # Your code goes here...
6
- end
7
- end