commit d8e565524f57940f38ef53ba1c7bb37ac896f205 Author: John Bintz Date: Fri Aug 10 11:35:06 2012 -0400 initial commit, still kinda hacking on it diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d8d62f --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp +.sass-cache/ + diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ac6d890 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in sprockets-assistant.gemspec +gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..87b491e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 John Bintz + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7376226 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Sprockets::Assistant + +TODO: Write a gem description + +## Installation + +Add this line to your application's Gemfile: + + gem 'sprockets-assistant' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install sprockets-assistant + +## Usage + +TODO: Write usage instructions here + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Added some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..f57ae68 --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +#!/usr/bin/env rake +require "bundler/gem_tasks" diff --git a/bin/sprockets-assistant b/bin/sprockets-assistant new file mode 100755 index 0000000..b7903ce --- /dev/null +++ b/bin/sprockets-assistant @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby + +$: << File.expand_path('../../lib', __FILE__) + +require 'sprockets/assistant/cli' + +Sprockets::Assistant::CLI.start + +# vim: filetype=ruby diff --git a/lib/sprockets-assistant.rb b/lib/sprockets-assistant.rb new file mode 100644 index 0000000..f2c0bce --- /dev/null +++ b/lib/sprockets-assistant.rb @@ -0,0 +1 @@ +require "sprockets/assistant" diff --git a/lib/sprockets/assistant.rb b/lib/sprockets/assistant.rb new file mode 100644 index 0000000..0da8391 --- /dev/null +++ b/lib/sprockets/assistant.rb @@ -0,0 +1,6 @@ +module Sprockets + module Assistant + + end +end + diff --git a/lib/sprockets/assistant/app_builder.rb b/lib/sprockets/assistant/app_builder.rb new file mode 100644 index 0000000..092706e --- /dev/null +++ b/lib/sprockets/assistant/app_builder.rb @@ -0,0 +1,49 @@ +require 'sprockets-vendor_gems/extend_all' +require 'sinatra/base' +require 'sinatra/sprockets' +require 'sprockets/assistant/compiler' + +module Sprockets + module Assistant + class AppBuilder + def initialize + instance_eval(File.read('assistant_config.rb')) + end + + def app(&block) + if block + @app = block + else + _app = @app + + Class.new(Sinatra::Base) do + set :root, Dir.pwd + + register Sinatra::Sprockets + + set :views, 'views' + + class_eval(&_app) + end + end + end + + def middleware(&block) + if block + @middleware = block + else + @middleware + end + end + + def compile(&block) + if block + @compile = block + else + Compiler.new(@compile).compile + end + end + end + end +end + diff --git a/lib/sprockets/assistant/cli.rb b/lib/sprockets/assistant/cli.rb new file mode 100644 index 0000000..bd8778b --- /dev/null +++ b/lib/sprockets/assistant/cli.rb @@ -0,0 +1,27 @@ +require 'sprockets/assistant/server' +require 'rack' +require 'thor' + +module Sprockets + module Assistant + class CLI < Thor + include Thor::Actions + source_root File.expand_path('../../../..', __FILE__) + + desc "server", "server" + def server + Rack::Handler.default.run(Sprockets::Assistant::Server.app) + end + + desc "compile", "compile things" + def compile + Sprockets::Assistant::AppBuilder.new.compile + end + + desc "create NAME", "initialize a new assistant project" + def create(name) + directory 'skel', name + end + end + end +end diff --git a/lib/sprockets/assistant/compiler.rb b/lib/sprockets/assistant/compiler.rb new file mode 100644 index 0000000..ac2598d --- /dev/null +++ b/lib/sprockets/assistant/compiler.rb @@ -0,0 +1,40 @@ +require 'sprockets' +require 'sprockets-vendor_gems/extend_all' +require 'pathname' +require 'sprockets/assistant/output' + +module Sprockets + module Assistant + class Compiler + include Sprockets::Assistant::Output + + DEFAULT_TARGET = "compiled" + + def initialize(settings) + @settings = settings + @target = DEFAULT_TARGET + end + + def compile + @env = Sprockets::Environment.new + @env.append_path('assets/javascripts') + @env.append_path('assets/stylesheets') + + instance_eval(&@settings) + end + + def file(name) + file_target = target.join(name) + say "#{name} => #{file_target}" + + file_target.parent.mkpath + target.join(name).open('w') { |fh| fh.print @env[name].to_s } + end + + def target + Pathname(@target) + end + end + end +end + diff --git a/lib/sprockets/assistant/output.rb b/lib/sprockets/assistant/output.rb new file mode 100644 index 0000000..4029fd7 --- /dev/null +++ b/lib/sprockets/assistant/output.rb @@ -0,0 +1,10 @@ +module Sprockets + module Assistant + module Output + def say(*args) + $stdout.puts(*args) + end + end + end +end + diff --git a/lib/sprockets/assistant/server.rb b/lib/sprockets/assistant/server.rb new file mode 100644 index 0000000..e3648f1 --- /dev/null +++ b/lib/sprockets/assistant/server.rb @@ -0,0 +1,41 @@ +require 'rack' + +module Sprockets + module Assistant + class Server + def self.app + new.app + end + + def initialize + require 'sprockets/assistant/app_builder' + + @app_builder = AppBuilder.new + end + + def call(env) + app.call(env) + end + + def app + _app_builder = @app_builder + _app = @app_builder.app + + Rack::Builder.app do + use Rack::CommonLogger, $stdout + + instance_eval(&_app_builder.middleware) + + map "/#{Sinatra::Sprockets.config.prefix}" do + $stderr.puts Sinatra::Sprockets.environment.inspect + + run Sinatra::Sprockets.environment + end + + run _app + end + end + end + end +end + diff --git a/lib/sprockets/assistant/version.rb b/lib/sprockets/assistant/version.rb new file mode 100644 index 0000000..94856ee --- /dev/null +++ b/lib/sprockets/assistant/version.rb @@ -0,0 +1,6 @@ +module Sprockets + module Assistant + VERSION = '0.0.1' + end +end + diff --git a/skel/Gemfile b/skel/Gemfile new file mode 100644 index 0000000..95bbfc0 --- /dev/null +++ b/skel/Gemfile @@ -0,0 +1,5 @@ +gem 'sprockets-assistant' + +gem 'thin' +gem 'compass' + diff --git a/skel/assets/javascripts/application.js.coffee b/skel/assets/javascripts/application.js.coffee new file mode 100644 index 0000000..aefad65 --- /dev/null +++ b/skel/assets/javascripts/application.js.coffee @@ -0,0 +1,2 @@ +alert "hello" + diff --git a/skel/assets/stylesheets/application.css.scss b/skel/assets/stylesheets/application.css.scss new file mode 100644 index 0000000..d39c405 --- /dev/null +++ b/skel/assets/stylesheets/application.css.scss @@ -0,0 +1,5 @@ +$color: green; + +body { + background-color: green; +} diff --git a/skel/assistant_config.rb b/skel/assistant_config.rb new file mode 100644 index 0000000..573be8c --- /dev/null +++ b/skel/assistant_config.rb @@ -0,0 +1,14 @@ +middleware do + # use Rack::LiveReload +end + +app do + get '/' do + erb :index + end +end + +compile do + file "application.js" + file "application.css" +end diff --git a/skel/views/index.erb b/skel/views/index.erb new file mode 100644 index 0000000..65a0eb6 --- /dev/null +++ b/skel/views/index.erb @@ -0,0 +1,11 @@ + + + Sprockets-assistant project + <%= javascript_include_tag :application %> + <%= stylesheet_link_tag :application %> + + +

It works!

+ + + diff --git a/sprockets-assistant.gemspec b/sprockets-assistant.gemspec new file mode 100644 index 0000000..ac43262 --- /dev/null +++ b/sprockets-assistant.gemspec @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +require File.expand_path('../lib/sprockets/assistant/version', __FILE__) + +Gem::Specification.new do |gem| + gem.authors = ["John Bintz"] + gem.email = ["john@coswellproductions.com"] + gem.description = %q{TODO: Write a gem description} + gem.summary = %q{TODO: Write a gem summary} + gem.homepage = "" + + gem.files = `git ls-files`.split($\) + gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) + gem.name = "sprockets-assistant" + gem.require_paths = ["lib"] + gem.version = Sprockets::Assistant::VERSION + + gem.add_dependency 'thor' + gem.add_dependency 'sinatra' + gem.add_dependency 'sinatra-sprockets-ext' + gem.add_dependency 'coffee-script' + gem.add_dependency 'sass' + gem.add_dependency 'sprockets-vendor_gems' +end +