convey 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Copyright 2011 Ashley Williams
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+
16
+ Ashley Williams
17
+ http://twitter.com/ashleyw
data/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Convey is Copyright (c) 2011 Ashley Williams
2
+ Convey is Apache 2.0 Licensed
3
+ Ashley Williams can be found at and contacted via http://twitter.com/ashleyw
4
+ The source can be found at http://github.com/ashleyw/Convey
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Convey
2
+ ### Simple Haml, Sass and CoffeeScript prototyping
3
+
4
+ Quickly hacked together one night. Not brilliant code, but it works. Patches welcome! ;)
5
+
6
+ ## Install
7
+
8
+ [sudo] gem install convey
9
+
10
+ ## Usage
11
+
12
+ $ convey init my_project
13
+
14
+ Creates a new skeleton project in `my_project`.
15
+
16
+
17
+ $ convey server
18
+
19
+ Starts a Sinatra server at `0.0.0.0:4567`. The root path maps to '/index.html'. Any .haml, .sass, or .coffee files will be rendered when a request comes in for the same file name but with the extension of .html, .css, or .js respectively.
20
+
21
+
22
+ $ convey compile
23
+
24
+ Compiles the project files into /compiled.
25
+
26
+ ## Issues? Ideas? Patches?
27
+ Please feel free to contact me!
28
+
29
+ ## Copyright and Licence
30
+
31
+ Apache 2.0 License - See LICENSE for details.
32
+ Copyright (c) 2011 [Ashley Williams](http://ashleyw.co.uk)
33
+
34
+ In short, you can use Convey for whatever you like commercial or not, but please include a brief credit (as in the NOTICE file - as per the Apache 2.0 License) somewhere deep in your license file or similar, and, if you're nice and have the time, let me know if you're using it and/or share any significant changes or improvements you make.
data/bin/convey ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ command, *options = ARGV
4
+
5
+ if command == "-h" or command == "help"
6
+ puts "Commands:"
7
+ puts " -h, help"
8
+ puts " -v, version"
9
+ puts " -i, init [dir]"
10
+ puts " -s, server"
11
+ puts " -c, compile [dir] (default: current directory)"
12
+ exit
13
+ end
14
+
15
+
16
+ begin
17
+ require 'convey'
18
+ rescue LoadError
19
+ require 'rubygems'
20
+ require 'convey'
21
+ end
22
+
23
+ include Convey
24
+
25
+ if command == "-v" or command == "version"
26
+ puts "Convey #{Convey::VERSION}"
27
+ elsif command == "init" or command == "-i"
28
+ template_path = File.expand_path "#{File.dirname(__FILE__)}/../template"
29
+ `mkdir #{options[0]}`
30
+ `cp -R #{template_path}/* #{options[0]}`
31
+ elsif command == "server" or command == "-s"
32
+ Convey::Server.run!
33
+ elsif command == "compile" or command == "-c"
34
+ dir = options[0] || Dir.pwd
35
+ Convey::Compiler.compile!(dir)
36
+ end
data/lib/convey.rb ADDED
@@ -0,0 +1,8 @@
1
+ $: << File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ require 'haml'
4
+ require 'sass'
5
+
6
+ require 'convey/main'
7
+ require 'convey/server'
8
+ require 'convey/compiler'
@@ -0,0 +1,62 @@
1
+ module Convey
2
+ class Compiler
3
+ include Convey
4
+
5
+ def self.compile!(base_path)
6
+ `rm -rf #{base_path}/compiled`
7
+ Dir.mkdir("#{base_path}/compiled")
8
+ files = Dir.glob("#{base_path}/**/*")
9
+ root = "#{base_path}/compiled"
10
+ files.each do |path|
11
+
12
+ if File.directory?(path)
13
+ unless path =~ /compiled/
14
+ Dir.mkdir("#{root}/#{path.gsub!(base_path, "")}")
15
+ end
16
+ next
17
+ end
18
+
19
+ meta = Convey::Compiler.process_file(path)
20
+ local_path = meta[:path].gsub(base_path, "")
21
+
22
+ if meta[:path] != path
23
+ puts "Compiled #{path.gsub(base_path, "")} to /compiled#{local_path}"
24
+ else
25
+ puts "Copied #{path.gsub(base_path, "")} to /compiled#{local_path}"
26
+ end
27
+
28
+ File.open("#{root}#{local_path}", 'w') {|f| f.write(meta[:data]) }
29
+ end
30
+ end
31
+
32
+ def self.process_file(path)
33
+ meta = {}
34
+ if File.exists?(path)
35
+ if path =~ /\.haml/
36
+ meta[:data] = Haml::Engine.new( File.read(path) ).render
37
+ meta[:type] = 'html'
38
+ meta[:path] = path.gsub(".haml", ".html")
39
+ elsif path =~ /\.sass/
40
+ meta[:data] = Sass::Engine.new( File.read(path) , :syntax => :sass).render
41
+ meta[:type] = 'css'
42
+ meta[:path] = path.gsub(".sass", ".css")
43
+ elsif path =~ /\.coffee/
44
+ if coffee_installed?
45
+ meta[:data] = `coffee -p #{path}`
46
+ meta[:type] = 'javascript'
47
+ meta[:path] = path.gsub(".coffee", ".js")
48
+ else
49
+ raise "CoffeeScript not installed! Run `brew install coffee` on OS X."
50
+ end
51
+ else
52
+ meta = {:data => File.read(path), :path => path, :type => path.split('.').last}
53
+ end
54
+ else
55
+ raise "Path '#{path}' doesn't exist."
56
+ end
57
+
58
+ return meta
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,14 @@
1
+ module Convey
2
+ VERSION = "0.1"
3
+
4
+ def coffee_installed?
5
+ begin
6
+ `coffee -v`
7
+ rescue
8
+ return false
9
+ end
10
+
11
+ return true
12
+ end
13
+
14
+ end
@@ -0,0 +1,24 @@
1
+ require 'sinatra/base'
2
+
3
+ module Convey
4
+ class Server < Sinatra::Base
5
+ include Convey
6
+
7
+ set :public, Dir.pwd
8
+
9
+ get '/|*.html|css|js' do
10
+ if env["PATH_INFO"] == '/'
11
+ env["PATH_INFO"] = '/index.html'
12
+ end
13
+
14
+ path = Dir.pwd + env["PATH_INFO"]
15
+ path.gsub!(".html", ".haml")
16
+ path.gsub!(".css", ".sass")
17
+ path.gsub!(".js", ".coffee")
18
+
19
+ meta = Convey::Compiler.process_file(path)
20
+ content_type "text/#{meta[:type]}"
21
+ return meta[:data]
22
+ end
23
+ end
24
+ end
Binary file
@@ -0,0 +1,10 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %link{:href => "/styles/main.css", :type => "text/css", :rel => "stylesheet"}
5
+ %body
6
+ %h1 Hello, Haml!
7
+
8
+ %img{:src => "/images/hello.png"}
9
+
10
+ %script{:src => "/js/main.js", :type => "text/javascript"}
@@ -0,0 +1 @@
1
+ alert "Hello, CoffeeScript!"
@@ -0,0 +1,7 @@
1
+ body
2
+ font-family: Georgia, serif
3
+ text-align: center
4
+
5
+ h1
6
+ font-size: 42px
7
+ font-style: italic
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: convey
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Ashley Williams
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-31 00:00:00 +01:00
18
+ default_executable: convey
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ version_requirements: *id001
33
+ name: sinatra
34
+ - !ruby/object:Gem::Dependency
35
+ prerelease: false
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: haml
48
+ description:
49
+ email:
50
+ executables:
51
+ - convey
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - bin/convey
58
+ - lib/convey/compiler.rb
59
+ - lib/convey/main.rb
60
+ - lib/convey/server.rb
61
+ - lib/convey.rb
62
+ - template/images/hello.png
63
+ - template/index.haml
64
+ - template/js/main.coffee
65
+ - template/styles/main.sass
66
+ - LICENSE
67
+ - NOTICE
68
+ - README.md
69
+ has_rdoc: true
70
+ homepage: http://ashleyw.co.uk/
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.4.2
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: "Convey: Haml, Sass and CoffeeScript prototyping"
103
+ test_files: []
104
+