liquid-eval 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +37 -0
- data/Rakefile +3 -0
- data/lib/liquid-eval.rb +46 -0
- data/lib/liquid-eval/version.rb +3 -0
- data/liquid-eval.gemspec +20 -0
- data/readme.md +24 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
liquid-eval (0.0.1)
|
5
|
+
jekyll
|
6
|
+
liquid
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
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)
|
23
|
+
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)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
liquid-eval!
|
data/Rakefile
ADDED
data/lib/liquid-eval.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'liquid-eval/version'
|
2
|
+
require 'liquid'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module LiquidEval
|
6
|
+
|
7
|
+
def self.register_language(language, interpreter, extension)
|
8
|
+
puts "Registering language #{language} with interpreter #{interpreter} and extension #{extension}."
|
9
|
+
end
|
10
|
+
|
11
|
+
class EvalBlock < ::Liquid::Block
|
12
|
+
def initialize(name, language, tokens)
|
13
|
+
super
|
14
|
+
@code = @nodelist[0].to_s.gsub(/^$\n/, '')
|
15
|
+
@code_html = CGI.escapeHTML(@code)
|
16
|
+
@language = language.strip
|
17
|
+
|
18
|
+
case @language
|
19
|
+
when 'ruby'
|
20
|
+
@result = interpret('ruby', 'rb')
|
21
|
+
when 'python'
|
22
|
+
@result = interpret('python', 'py')
|
23
|
+
when 'perl'
|
24
|
+
@result = interpret('perl', 'pl')
|
25
|
+
when 'php'
|
26
|
+
@result = interpret('php', 'php')
|
27
|
+
else
|
28
|
+
@result = 'Language not currently supported by Liquid::EvalBlock.'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def render(context)
|
33
|
+
%Q[<h6>Code:</h6><pre><code>#{@code_html}</code></pre><h6>Output:</h6><pre class="output"><code>#{@result}</code></pre>]
|
34
|
+
end
|
35
|
+
|
36
|
+
def interpret(interpreter, extension)
|
37
|
+
filename = "/tmp/#{interpreter}-codeblock.#{extension}"
|
38
|
+
File.open(filename, 'w') {|f| f.write(@code)}
|
39
|
+
@result = `#{interpreter} #{filename}`
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
::Liquid::Template.register_tag 'eval', LiquidEval::EvalBlock
|
46
|
+
|
data/liquid-eval.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "liquid-eval/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "liquid-eval"
|
6
|
+
s.version = LiquidEval::VERSION
|
7
|
+
s.authors = ["Brian Kelly"]
|
8
|
+
s.email = ["polymonic@gmail.com"]
|
9
|
+
s.homepage = "http://github.com/spilth/liquid-eval"
|
10
|
+
s.summary = %q{Embedded Code and Output for Liquid}
|
11
|
+
s.description = %q{Exexcutes code blocks and appends the generated output after the example code.}
|
12
|
+
|
13
|
+
s.rubyforge_project = "liquid-eval"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.add_runtime_dependency('liquid')
|
19
|
+
end
|
20
|
+
|
data/readme.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Liquid Eval Block
|
2
|
+
|
3
|
+
Allows you to embed a block of code in your page as well as the output generated by that code.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
- Install the gem or add it to your projects `Gemfile`.
|
8
|
+
- Use `require 'liquid-eval'` somewhere in your code
|
9
|
+
- For Jekyll projects, add this to a file in your `_plugins` directory.
|
10
|
+
|
11
|
+
Within a post or page you can now do:
|
12
|
+
|
13
|
+
{% eval ruby %}
|
14
|
+
puts "Hello, world!"
|
15
|
+
{% endeval %}
|
16
|
+
|
17
|
+
This will generate the following HTML in your page:
|
18
|
+
|
19
|
+
<h6>Code:</h6>
|
20
|
+
<pre><code>puts "Hello, world!"</code></pre>
|
21
|
+
|
22
|
+
<h6>Output:</h6>
|
23
|
+
<pre class="output"><code>Hello, world!</code></pre>
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: liquid-eval
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Kelly
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: liquid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Exexcutes code blocks and appends the generated output after the example
|
31
|
+
code.
|
32
|
+
email:
|
33
|
+
- polymonic@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- Rakefile
|
42
|
+
- lib/liquid-eval.rb
|
43
|
+
- lib/liquid-eval/version.rb
|
44
|
+
- liquid-eval.gemspec
|
45
|
+
- readme.md
|
46
|
+
homepage: http://github.com/spilth/liquid-eval
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project: liquid-eval
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Embedded Code and Output for Liquid
|
70
|
+
test_files: []
|
71
|
+
has_rdoc:
|