liquid-eval 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format documentation
3
+
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+
data/Gemfile.lock CHANGED
@@ -1,37 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- liquid-eval (0.0.1)
5
- jekyll
4
+ liquid-eval (0.0.2)
6
5
  liquid
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
- classifier (1.3.3)
12
- fast-stemmer (>= 1.0.0)
13
- directory_watcher (1.4.1)
14
- fast-stemmer (1.0.1)
15
- jekyll (0.12.0)
16
- classifier (~> 1.3)
17
- directory_watcher (~> 1.1)
18
- kramdown (~> 0.13.4)
19
- liquid (~> 2.3)
20
- maruku (~> 0.5)
21
- pygments.rb (~> 0.3.2)
22
- kramdown (0.13.8)
10
+ diff-lcs (1.1.3)
11
+ guard (1.3.3)
12
+ listen (>= 0.4.2)
13
+ thor (>= 0.14.6)
14
+ guard-rspec (1.2.1)
15
+ guard (>= 1.1)
23
16
  liquid (2.4.1)
24
- maruku (0.6.1)
25
- syntax (>= 1.0.0)
26
- posix-spawn (0.3.6)
27
- pygments.rb (0.3.7)
28
- posix-spawn (~> 0.3.6)
29
- yajl-ruby (~> 1.1.0)
30
- syntax (1.0.0)
31
- yajl-ruby (1.1.0)
17
+ listen (0.5.1)
18
+ rake (10.0.3)
19
+ rspec (2.11.0)
20
+ rspec-core (~> 2.11.0)
21
+ rspec-expectations (~> 2.11.0)
22
+ rspec-mocks (~> 2.11.0)
23
+ rspec-core (2.11.1)
24
+ rspec-expectations (2.11.3)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.11.3)
27
+ thor (0.17.0)
32
28
 
33
29
  PLATFORMS
34
30
  ruby
35
31
 
36
32
  DEPENDENCIES
33
+ guard-rspec
37
34
  liquid-eval!
35
+ rake
36
+ rspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
2
4
  Bundler::GemHelper.install_tasks
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
3
8
 
data/lib/liquid-eval.rb CHANGED
@@ -9,6 +9,8 @@ module LiquidEval
9
9
  end
10
10
 
11
11
  class EvalBlock < ::Liquid::Block
12
+ attr_reader :code_html, :result
13
+
12
14
  def initialize(name, language, tokens)
13
15
  super
14
16
  @code = @nodelist[0].to_s.gsub(/^$\n/, '')
@@ -24,19 +26,25 @@ module LiquidEval
24
26
  @result = interpret('perl', 'pl')
25
27
  when 'php'
26
28
  @result = interpret('php', 'php')
29
+ when 'bash'
30
+ @result = interpret('bash', 'sh')
27
31
  else
28
32
  @result = 'Language not currently supported by Liquid::EvalBlock.'
29
33
  end
30
34
  end
31
35
 
32
36
  def render(context)
33
- %Q[<h6>Code:</h6><pre><code>#{@code_html}</code></pre><h6>Output:</h6><pre class="output"><code>#{@result}</code></pre>]
37
+ if @result == ""
38
+ %Q[<h6>Code:</h6><pre><code>#{@code_html}</code></pre>]
39
+ else
40
+ %Q[<h6>Code:</h6><pre><code>#{@code_html}</code></pre><h6>Output:</h6><pre class="output"><code>#{@result}</code></pre>]
41
+ end
34
42
  end
35
43
 
36
44
  def interpret(interpreter, extension)
37
45
  filename = "/tmp/#{interpreter}-codeblock.#{extension}"
38
46
  File.open(filename, 'w') {|f| f.write(@code)}
39
- @result = `#{interpreter} #{filename}`
47
+ CGI.escapeHTML(`#{interpreter} #{filename} 2>&1`)
40
48
  end
41
49
 
42
50
  end
@@ -1,3 +1,3 @@
1
1
  module LiquidEval
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/liquid-eval.gemspec CHANGED
@@ -16,5 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_runtime_dependency('liquid')
19
+
20
+ s.add_development_dependency "rake"
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "guard-rspec"
19
23
  end
20
24
 
data/readme.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/spilth/liquid-eval.png?branch=master)](https://travis-ci.org/spilth/liquid-eval)
2
+
1
3
  # Liquid Eval Block
2
4
 
3
5
  Allows you to embed a block of code in your page as well as the output generated by that code.
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe LiquidEval::EvalBlock do
4
+ include Liquid
5
+
6
+ it "captures program output" do
7
+ template = Liquid::Template.parse('{% eval ruby %}puts "Hello, Ruby!"{% endeval %}')
8
+ template.root.nodelist[0].result.should eq "Hello, Ruby!\n"
9
+ end
10
+
11
+ it "captures program errors" do
12
+ template = Liquid::Template.parse('{% eval ruby %}puts foo.to_s{% endeval %}')
13
+ template.root.nodelist[0].result.should include "NameError"
14
+ end
15
+
16
+ it "escapes HTML characters in errors" do
17
+ template = Liquid::Template.parse('{% eval python %}foo{% endeval %}')
18
+ template.root.nodelist[0].result.should_not include "<module>"
19
+ end
20
+
21
+ it "doesn't produce an output code block when there's no output" do
22
+ template = Liquid::Template.parse('{% eval ruby %}class Foo;end{% endeval %}')
23
+ template.root.nodelist[0].code_html.should_not include '<pre class="output">'
24
+ end
25
+
26
+ end
27
+
28
+
@@ -0,0 +1,2 @@
1
+ require File.expand_path("../../lib/liquid-eval", __FILE__)
2
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid-eval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-02 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: liquid
@@ -27,6 +27,54 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
30
78
  description: Exexcutes code blocks and appends the generated output after the example
31
79
  code.
32
80
  email:
@@ -36,13 +84,18 @@ extensions: []
36
84
  extra_rdoc_files: []
37
85
  files:
38
86
  - .gitignore
87
+ - .rspec
88
+ - .travis.yml
39
89
  - Gemfile
40
90
  - Gemfile.lock
91
+ - Guardfile
41
92
  - Rakefile
42
93
  - lib/liquid-eval.rb
43
94
  - lib/liquid-eval/version.rb
44
95
  - liquid-eval.gemspec
45
96
  - readme.md
97
+ - spec/lib/liquid-eval_spec.rb
98
+ - spec/spec_helper.rb
46
99
  homepage: http://github.com/spilth/liquid-eval
47
100
  licenses: []
48
101
  post_install_message:
@@ -55,12 +108,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
108
  - - ! '>='
56
109
  - !ruby/object:Gem::Version
57
110
  version: '0'
111
+ segments:
112
+ - 0
113
+ hash: 631344837489675618
58
114
  required_rubygems_version: !ruby/object:Gem::Requirement
59
115
  none: false
60
116
  requirements:
61
117
  - - ! '>='
62
118
  - !ruby/object:Gem::Version
63
119
  version: '0'
120
+ segments:
121
+ - 0
122
+ hash: 631344837489675618
64
123
  requirements: []
65
124
  rubyforge_project: liquid-eval
66
125
  rubygems_version: 1.8.24
@@ -68,4 +127,3 @@ signing_key:
68
127
  specification_version: 3
69
128
  summary: Embedded Code and Output for Liquid
70
129
  test_files: []
71
- has_rdoc: