Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b878b1bb124eef6dfecafbf02325c1298664ff1d @jnicklas jnicklas committed Feb 2, 2012
@@ -0,0 +1,17 @@
+*.gem
+*.rbc
+.bundle
+.config
+.yardoc
+Gemfile.lock
+InstalledFiles
+_yardoc
+coverage
+doc/
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
@@ -0,0 +1,4 @@
+source 'http://rubygems.org'
+
+# Specify your gem's dependencies in serenade_rails.gemspec
+gemspec
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,7 @@
+require 'serenade_rails/version'
+require 'serenade_rails/processor'
+require 'serenade_rails/engine'
+require 'serenade_rails/template'
+
+module SerenadeRails
+end
@@ -0,0 +1,4 @@
+module SerenadeRails
+ class Engine < ::Rails::Engine
+ end
+end
@@ -0,0 +1,26 @@
+require 'sprockets/engines'
+require 'tilt'
+require 'action_view'
+require 'action_view/helpers'
+require 'action_view/helpers/javascript_helper'
+
+module Sprockets
+ class SerenadeProcessor < Tilt::Template
+ include ActionView::Helpers::JavaScriptHelper
+
+ def self.default_mime_type
+ 'application/javascript'
+ end
+
+ def prepare
+ end
+
+ def evaluate(scope, locals, &block)
+ name = scope.logical_path.gsub(/^views\//, "")
+ SerenadeRails::Template.new(name, data.dup).render
+ end
+ end
+
+ register_engine '.serenade', ::Sprockets::SerenadeProcessor
+end
+
@@ -0,0 +1,25 @@
+require 'execjs'
+require 'active_support/json'
+
+module SerenadeRails
+ SERENADE_PATH = File.expand_path('../assets/javascripts/serenade.js', File.dirname(__FILE__))
+
+ class Template
+ attr_reader :name, :content
+
+ def initialize(name, content)
+ @name = name
+ @content = content
+ end
+
+ def parse
+ context = ExecJS.compile(File.read(SERENADE_PATH))
+ code = "Serenade.view(#{content.to_json}).parse()"
+ context.eval(code)
+ end
+
+ def render
+ "Serenade.view(#{name.to_json}, #{parse.to_json});"
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module SerenadeRails
+ VERSION = "0.1.0"
+end
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/serenade_rails/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Jonas Nicklas"]
+ gem.email = ["jonas.nicklas@gmail.com"]
+ gem.description = %q{Use Serenade.js within the Rails asset pipeline}
+ gem.summary = %q{Serenade.js for Rails}
+ gem.homepage = ""
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "serenade_rails"
+ gem.require_paths = ["lib"]
+ gem.version = SerenadeRails::VERSION
+
+ gem.add_dependency "rails", "~> 3.1"
+ gem.add_dependency "execjs", ">= 0.3.0"
+end

0 comments on commit b878b1b

Please sign in to comment.