Permalink
Browse files

Changing structure of sweet an integration with Rails, closing issues #…

  • Loading branch information...
1 parent 4488ebc commit 9255862e768cad3fef2c5d4e34b5faede38b8e6d @joaomdmoura committed Mar 21, 2012
Showing with 70 additions and 38 deletions.
  1. +1 −1 README.md
  2. +7 −0 lib/railtie.rb
  3. +1 −1 lib/runtime.rb
  4. +1 −1 lib/runtime/bootstrap.rb
  5. +58 −33 lib/sweet.rb
  6. +2 −2 sweet.gemspec
View
@@ -1,5 +1,5 @@
![Alt text](http://joaomdmoura.github.com/sweet/assets/images/logo.png "A Sweet Language")
-# Sweet (current version - 0.4.6)
+# Sweet (current version - 0.6.6)
A **Sweet** Language, that compiles for HTML.
Description
View
@@ -0,0 +1,7 @@
+module SweetLang
+ class Railtie < Rails::Railtie
+ initializer "template handler registration" do
+ ActionView::Template.register_template_handler :s, ::SweetLang::Sweet.new
+ end
+ end
+end
View
@@ -1,4 +1,4 @@
-@code = []
+$code = []
require "runtime/object"
require "runtime/class"
View
@@ -36,7 +36,7 @@
# Print an object to the console.
# eg.: print("hi there!")
Runtime["Object"].runtime_methods["print"] = proc do |receiver, arguments|
- @code << arguments.first.ruby_value
+ $code << arguments.first.ruby_value
Runtime["nil"]
end
View
@@ -1,71 +1,96 @@
#!/usr/bin/env ruby
+dir = File.dirname(__FILE__)
+$LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
require "interpreter"
require "readline"
require "treat"
require "trollop"
require "filesystemwatcher"
+require "railtie" if defined?(Rails)
-class Sweet
+module SweetLang
+ class Sweet
- def parsing_options
+ def initialize ( view=nil )
+ @view = view
+ end
+
+ def call ( template )
+ treat = Treat.new
+ interpreter = Interpreter.new
+ interpreter.eval ( template.source )
+ new_code = treat.indent( $code )
+ $code = []
+ new_code.inspect
+ end
- opts = Trollop::options do
- version "Sweet 0.4.6 (c) 2012 Joao Moura a.k.a D3TR1"
- banner <<-EOS
- A Sweet Language, that compiles for HTML.
+ def parsing_options
- Usage:
- sweet [options] <filename> or <path>
+ opts = Trollop::options do
+ version "Sweet 0.6.6 (c) 2012 Joao Moura a.k.a D3TR1"
+ banner <<-EOS
+ A Sweet Language, that compiles for HTML.
- Examples:
- sweet -c example.s
- sweet -w ./
- sweet -o
+ Usage:
+ sweet [options] <filename> or <path>
- Options:
- EOS
+ Examples:
+ sweet -c example.s
+ sweet -w ./
+ sweet -o
+
+ Options:
+ EOS
+
+ opt :compile, "Compile a single file", :type => :string
+ opt :watch, "Watch a directory", :type => :string
+ opt :console, "Open SIC ( Sweet Interactive Console )"
+ end
+ Trollop::die :compile, "the file must exist" unless File.exist?(opts[:compile]) if opts[:compile]
+ return opts
- opt :compile, "Compile a single file", :type => :string
- opt :watch, "Watch a directory", :type => :string
- opt :console, "Open SIC ( Sweet Interactive Console )"
end
- Trollop::die :compile, "the file must exist" unless File.exist?(opts[:compile]) if opts[:compile]
- return opts
- end
+ def sic
- def sic
+ puts "Sweet Interactive Console, CTRL+C to quit"
+ loop do
+ line = Readline::readline(">> ")
+ Readline::HISTORY.push(line)
+ value = interpreter.eval(line)
+ puts "=> #{value.ruby_value.inspect}"
+ end
- puts "Sweet Interactive Console, CTRL+C to quit"
- loop do
- line = Readline::readline(">> ")
- Readline::HISTORY.push(line)
- value = interpreter.eval(line)
- puts "=> #{value.ruby_value.inspect}"
end
+ def engine( old_code )
+ treat = Treat.new
+ interpreter = Interpreter.new
+ interpreter.eval (old_code)
+ new_code = treat.indent( $code )
+ $code = []
+ return "print('#{new_code}')"
+ end
end
-
end
-def compile_file(file)
+def compile_file( file )
treat = Treat.new
$path = file.split(/[ =-_a-zA-Z0-9]+\.s/)[0]
interpreter = Interpreter.new
@filename = file.split(".")[0]
interpreter.eval File.read(file)
File.open("#{@filename}.html", 'w+') do |f|
- f.puts treat.indent( @code )
+ f.puts treat.indent( $code )
end
puts "Sweet code compiled!"
- @code = []
+ $code = []
end
-sweet = Sweet.new
+sweet = ::SweetLang::Sweet.new
opts = sweet.parsing_options
-
# Compile a single file
if opts[:compile]
compile_file(opts[:compile])
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'sweet-lang'
- s.version = '0.4.6'
+ s.version = '0.6.6'
s.executables << 'sweet'
s.date = '2012-01-11'
s.summary = "A Sweet language, that compiles for HTML"
@@ -12,6 +12,6 @@ Gem::Specification.new do |s|
before really right and compile it."
s.authors = ["João Moura"]
s.email = 'joaomdmoura@gmail.com'
- s.files = ["lib/sweet.rb", "lib/interpreter.rb", "lib/treat.rb", "lib/lexer.rb", "lib/nodes.rb", "lib/parser.rb", "lib/runtime.rb", "lib/lexer/core.rb", "lib/lexer/strings.rb", "lib/lexer/tags.rb", "lib/lexer/files.rb", "lib/runtime/bootstrap.rb", "lib/runtime/class.rb", "lib/runtime/context.rb", "lib/runtime/method.rb", "lib/runtime/object.rb", "lib/trollop.rb", "lib/filesystemwatcher.rb", "lib/servicestate.rb"]
+ s.files = Dir[ 'lib/*', 'lib/**/*', 'init.rb', 'bin/sweet' ]
s.homepage = 'http://joaomdmoura.github.com/sweet/'
end

0 comments on commit 9255862

Please sign in to comment.