hotcell 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +15 -0
  5. data/Guardfile +24 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +17 -0
  9. data/hotcell.gemspec +22 -0
  10. data/lib/hotcell/.DS_Store +0 -0
  11. data/lib/hotcell/config.rb +31 -0
  12. data/lib/hotcell/context.rb +36 -0
  13. data/lib/hotcell/errors.rb +43 -0
  14. data/lib/hotcell/extensions.rb +42 -0
  15. data/lib/hotcell/lexer.rb +783 -0
  16. data/lib/hotcell/lexer.rl +299 -0
  17. data/lib/hotcell/manipulator.rb +31 -0
  18. data/lib/hotcell/node/arrayer.rb +7 -0
  19. data/lib/hotcell/node/assigner.rb +11 -0
  20. data/lib/hotcell/node/block.rb +58 -0
  21. data/lib/hotcell/node/calculator.rb +35 -0
  22. data/lib/hotcell/node/command.rb +41 -0
  23. data/lib/hotcell/node/hasher.rb +7 -0
  24. data/lib/hotcell/node/joiner.rb +7 -0
  25. data/lib/hotcell/node/sequencer.rb +7 -0
  26. data/lib/hotcell/node/summoner.rb +11 -0
  27. data/lib/hotcell/node/tag.rb +26 -0
  28. data/lib/hotcell/node.rb +55 -0
  29. data/lib/hotcell/parser.rb +1186 -0
  30. data/lib/hotcell/parser.y +231 -0
  31. data/lib/hotcell/scope.rb +57 -0
  32. data/lib/hotcell/template.rb +29 -0
  33. data/lib/hotcell/version.rb +3 -0
  34. data/lib/hotcell.rb +19 -0
  35. data/misc/rage.rl +1999 -0
  36. data/misc/unicode2ragel.rb +305 -0
  37. data/spec/data/dstrings +8 -0
  38. data/spec/data/sstrings +6 -0
  39. data/spec/lib/hotcell/config_spec.rb +57 -0
  40. data/spec/lib/hotcell/context_spec.rb +53 -0
  41. data/spec/lib/hotcell/lexer_spec.rb +340 -0
  42. data/spec/lib/hotcell/manipulator_spec.rb +64 -0
  43. data/spec/lib/hotcell/node/block_spec.rb +188 -0
  44. data/spec/lib/hotcell/node/command_spec.rb +71 -0
  45. data/spec/lib/hotcell/parser_spec.rb +382 -0
  46. data/spec/lib/hotcell/scope_spec.rb +160 -0
  47. data/spec/lib/hotcell/template_spec.rb +41 -0
  48. data/spec/lib/hotcell_spec.rb +8 -0
  49. data/spec/spec_helper.rb +44 -0
  50. metadata +139 -0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ *.out
19
+ *.dot
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@hotcell --create
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hotcell.gemspec
4
+ gemspec
5
+
6
+ gem 'awesome_print'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'rb-inotify', require: false
13
+ gem 'rb-fsevent', require: false
14
+ gem 'rb-fchange', require: false
15
+ end
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' 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
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 pyromaniac
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,29 @@
1
+ # Hotcell
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hotcell'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hotcell
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ namespace :build do
4
+ desc 'Build lexer'
5
+ task :lexer do
6
+ `ragel -R -T0 lib/hotcell/lexer.rl`
7
+ end
8
+
9
+ task :dot do
10
+ `ragel -Vp lib/hotcell/lexer.rl > lexer.dot`
11
+ end
12
+
13
+ desc 'Build parser'
14
+ task :parser do
15
+ `racc -d -o lib/hotcell/parser.rb -O lib/hotcell/parser.out lib/hotcell/parser.y`
16
+ end
17
+ end
data/hotcell.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hotcell/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "hotcell"
8
+ gem.version = Hotcell::VERSION
9
+ gem.authors = ["pyromaniac"]
10
+ gem.email = ["kinwizard@gmail.com"]
11
+ gem.description = %q{Sandboxed ruby template processor}
12
+ gem.summary = %q{Sandboxed ruby template processor}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency "activesupport"
21
+ gem.add_runtime_dependency "racc"
22
+ end
Binary file
@@ -0,0 +1,31 @@
1
+ require 'singleton'
2
+
3
+ module Hotcell
4
+ class Config
5
+ include Singleton
6
+
7
+ attr_reader :commands, :blocks, :subcommands
8
+
9
+ def initialize
10
+ @commands = {}
11
+ @blocks = {}
12
+ @subcommands = {}
13
+ end
14
+
15
+ def register_command name, klass
16
+ name = name.to_s
17
+ if klass < ::Hotcell::Block
18
+ raise "Command `#{name}` already defined, you can not define block with the same name" if commands.key?(name)
19
+ blocks[name] = klass
20
+ klass.subcommands.each do |subcommand|
21
+ subcommands[subcommand] = klass
22
+ end
23
+ elsif klass < ::Hotcell::Command
24
+ raise "Block `#{name}` already defined, you can not define command with the same name" if blocks.key?(name)
25
+ commands[name] = klass
26
+ else
27
+ raise "Cannot register command `#{name}` because handler is not a Hotcell::Command or Hotcell::Block"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ require 'hotcell/scope'
2
+
3
+ module Hotcell
4
+ class Context
5
+ attr_reader :scope, :rescuer, :reraise
6
+ delegate :[], :[]=, :key?, :scoped, to: :scope
7
+
8
+ DEFAULT_RESCUER = ->(e){ "#{e.class}: #{e.message}" }
9
+
10
+ def initialize options = {}
11
+ options = options.dup
12
+
13
+ scope = options.delete(:scope) || {}
14
+ scope.merge! (options.delete(:variables) || {}).stringify_keys
15
+ scope.merge! (options.delete(:environment) || {}).symbolize_keys
16
+
17
+ @rescuer = options.delete(:rescuer) || DEFAULT_RESCUER
18
+ @reraise = !!options.delete(:reraise)
19
+
20
+ @scope = Scope.new scope.merge!(options.stringify_keys)
21
+ end
22
+
23
+ def safe *default
24
+ yield
25
+ rescue => e
26
+ rescue_result = rescuer.call(e)
27
+ default.size > 0 ? default.first : rescue_result
28
+ ensure
29
+ raise e if e && reraise
30
+ end
31
+
32
+ def manipulator_invoke method, *arguments
33
+ scope[method]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ module Hotcell
2
+ class Errors
3
+ class ParseError < StandardError
4
+ def initialize line, column
5
+ @line, @column = line, column
6
+ end
7
+ end
8
+
9
+ class UnexpectedSymbol < ParseError
10
+ def message
11
+ "Unexpected symbol at #{@line}:#{@column}"
12
+ end
13
+ end
14
+
15
+ class UnterminatedString < ParseError
16
+ def message
17
+ "Unterminated string starting at #{@line}:#{@column}"
18
+ end
19
+ end
20
+
21
+ # class UnterminatedRegexp < ParseError
22
+ # def message
23
+ # "Unterminated regexp starting at: line #{@line}, column #{@column}"
24
+ # end
25
+ # end
26
+
27
+ class SyntaxError < StandardError
28
+ def initialize message, line = nil, column = nil
29
+ @message, @line, @column = message, line, column
30
+ end
31
+
32
+ def message
33
+ "#{@message} at #{@line}:#{@column}"
34
+ end
35
+ end
36
+
37
+ class BlockError < SyntaxError
38
+ end
39
+
40
+ class ArgumentError < SyntaxError
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ NilClass.class_eval do
2
+ include Hotcell::Manipulator::Mixin
3
+ end
4
+
5
+ TrueClass.class_eval do
6
+ include Hotcell::Manipulator::Mixin
7
+ end
8
+
9
+ FalseClass.class_eval do
10
+ include Hotcell::Manipulator::Mixin
11
+ end
12
+
13
+ Numeric.class_eval do
14
+ include Hotcell::Manipulator::Mixin
15
+ end
16
+
17
+ String.class_eval do
18
+ include Hotcell::Manipulator::Mixin
19
+ end
20
+
21
+ Regexp.class_eval do
22
+ include Hotcell::Manipulator::Mixin
23
+ end
24
+
25
+ Time.class_eval do
26
+ include Hotcell::Manipulator::Mixin
27
+ end
28
+
29
+ Date.class_eval do
30
+ include Hotcell::Manipulator::Mixin
31
+ end
32
+
33
+ Array.class_eval do
34
+ include Hotcell::Manipulator::Mixin
35
+ end
36
+
37
+ Hash.class_eval do
38
+ include Hotcell::Manipulator::Mixin
39
+ end
40
+
41
+
42
+