tau 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tau.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ Tau
2
+ ===
3
+
4
+ Tau provides you write code of webpages using modern technologies such as
5
+ haml, sass, coffee-script. You dont't need to compile your code to HTML and
6
+ CSS by hand everytime you something change.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install tau
12
+
13
+ Usage
14
+ -----
15
+
16
+ It's pretty simple.
17
+
18
+ ### Getting started
19
+
20
+ 1. Start new coding project and switch to that. In the command prompt run:
21
+
22
+ `tau new example.com; cd example.com` *(where example.com is the project name)*
23
+
24
+ 2. Create html or haml file on code directory:
25
+
26
+ `echo "%h1 Hello <strong>tau</strong>!" > code/hello.haml`
27
+
28
+ 3. Start server and go to [http://localhost:15000/hello.html](http://localhost:15000/hello.html):
29
+
30
+ `tau server`
31
+
32
+ Attend even if you write hello.**haml** file you can see it by hello.**html**
33
+ in browser.
34
+
35
+ ### Creating new project
36
+
37
+ Run `tau new projectname` and tau will make directory tree for you:
38
+
39
+ projectname
40
+ |--code - for your .html and .haml files
41
+ | |--js - for .js and .coffee files
42
+ | |--css - for .css, .sass and .scss
43
+ | `--img - for any type of images
44
+ |
45
+ `--tau.yaml - config file
46
+
47
+ ### Coding
48
+
49
+ Run `tau server` in your project directory. Then put any html or haml files
50
+ into **code** directory, js or coffee files into **code/js**, css, sass or
51
+ scss into **code/css**. Now you can view files in browser by
52
+ http://localhost:15000/page.html or http://localhost:15000/css/style.css or
53
+ http://localhost:15000/js/script.js.
54
+
55
+ Attend that tau changes files extensions in browser from haml to html, from
56
+ coffee to js, from sass and scss to css. For example if you have
57
+ **code/js/myscript.coffee** file you can see it in browser by
58
+ http://localhost:15000/js/myscript.js.
59
+
60
+ In html or haml file you can include scripts written in coffee and styles
61
+ written in sass or scss. For example if you have **code/js/script.coffee**
62
+ script and **code/js/style.sass** spreadsheet you can include it to html by
63
+ lines:
64
+ ```html
65
+ <script src='js/script.js' type="text/javascript"></script>
66
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
67
+ ```
68
+ Anytime you change any file you can see updated version in browser. You don't
69
+ need to compile anything by hand.
70
+
71
+ License
72
+ -------
73
+
74
+ You can use tau by MIT License.
75
+
76
+ Contributing
77
+ ------------
78
+
79
+ Feel free to fork and pull request.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/tau ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tau/server'
3
+ require 'tau/projecter'
4
+
5
+ Tau::Server.start if ARGV.first == "server"
6
+ if ARGV.first == "new"
7
+ project_name = ARGV[1]
8
+ begin
9
+ Tau::Projecter.new_project(Dir.pwd, project_name)
10
+ rescue Exception => e
11
+ puts e.message
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ Feature: Making new projects
2
+ In order to avoid making project directory myself
3
+ As a web developer
4
+ I want tau make project for me
5
+
6
+ Scenario: making new project by tau
7
+ When I successfully run `tau new testproject`
8
+ And there should be right project directory "testproject"
@@ -0,0 +1,49 @@
1
+ Feature: Server
2
+ In order to compile all files by hand
3
+ As a web developer
4
+ I want tau server do it for me
5
+
6
+ Background: changing directory
7
+ Given I'm on sandbox project directory
8
+
9
+ Scenario: runtime haml compilation
10
+ Given a file named "code/hamltest.haml" with:
11
+ """
12
+ %h1 Hello, world!
13
+ %strong I'm tau ;)
14
+ """
15
+ When I go in browser to "http://localhost:15000/hamltest.html"
16
+ Then I should see html compiled from haml in "code/hamltest.haml"
17
+
18
+ Scenario: runtime coffee-script compilation
19
+ Given a file named "code/js/coffeetest.coffee" with:
20
+ """
21
+ square = (x) -> x * x
22
+ cube = (x) -> square(x) * x
23
+ """
24
+ When I go in browser to "http://localhost:15000/js/coffeetest.js"
25
+ Then I should see js compiled from coffee-script in "code/js/coffeetest.coffee"
26
+
27
+ Scenario: runtime sass compilation
28
+ Given a file named "code/css/sasstest.sass" with:
29
+ """
30
+ $blue: #3bbfce
31
+ .content-navigation
32
+ border-color: $blue
33
+ color: darken($blue, 9%)
34
+ """
35
+ When I go in browser to "http://localhost:15000/css/sasstest.css"
36
+ Then I should see css compiled from sass in "code/css/sasstest.sass"
37
+
38
+ Scenario: runtime scss compilation
39
+ Given a file named "code/css/scsstest.scss" with:
40
+ """
41
+ $blue: #3bbfce;
42
+ .content-navigation {
43
+ border-color: $blue;
44
+ color:
45
+ darken($blue, 9%);
46
+ }
47
+ """
48
+ When I go in browser to "http://localhost:15000/css/scsstest.css"
49
+ Then I should see css compiled from scss in "code/css/scsstest.scss"
@@ -0,0 +1,10 @@
1
+ Then /^there should be right project directory "(.*)"$/ do |project_dir|
2
+ tau_dirs = ['/code', 'code/js', 'code/css', 'code/img'].map { |dir| "#{project_dir}/#{dir}" }
3
+ check_directory_presence(tau_dirs, true)
4
+ tau_files = ['tau.yaml'].map { |file| "#{project_dir}/#{file}" }
5
+ check_file_presence(tau_files, true)
6
+ end
7
+
8
+ Given /^I'm on sandbox project directory$/ do
9
+ @dirs = [SANDBOX_PROJECT_DIR]
10
+ end
@@ -0,0 +1,29 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'haml'
4
+ require 'sass'
5
+ require 'coffee-script'
6
+
7
+ When /^I go in browser to "(.*)"$/ do |url|
8
+ @response = Net::HTTP.get_response(URI url).body
9
+ end
10
+
11
+ Then /^I should see:$/ do |string|
12
+ @response.should == string
13
+ end
14
+
15
+ # TODO: move it in more appropriate place
16
+ def render(content, lang)
17
+ return Haml::Engine.new(content).render if lang == 'haml'
18
+ return Sass::Engine.new(content).render if lang == 'sass'
19
+ return Sass::Engine.new(content, syntax: :scss).render if lang == 'scss'
20
+ return CoffeeScript.compile(content) if lang == 'coffee-script'
21
+ end
22
+
23
+ Then /^I should see (html|css|js) compiled from (haml|sass|scss|coffee-script) in "(.*)"$/ do |type, lang, filename|
24
+ file_content = nil
25
+ in_current_dir do
26
+ file_content = File.read(filename)
27
+ end
28
+ @response.should == render(file_content, lang)
29
+ end
@@ -0,0 +1,83 @@
1
+ # Copyright 2011 Solano Labs All Rights Reserved
2
+
3
+ require 'aruba/api'
4
+
5
+ class CukeGem
6
+ @setup_done = false
7
+
8
+ class << self
9
+ include Aruba::Api
10
+
11
+ attr_reader :setup_done
12
+
13
+ def setup(gemspec, verbose = true, once=true)
14
+ @verbose = verbose
15
+ puts "Setup test environment for gem." if @verbose
16
+ gem_home = setup_env
17
+ if !@setup_done || !once then
18
+ @setup_done = true
19
+ mkgemdir(gem_home)
20
+ gem_install(gemspec)
21
+ end
22
+ end
23
+
24
+ def teardown
25
+ restore_env
26
+ end
27
+
28
+ def setup_env
29
+ gem_home = File.join('tmp', 'sandbox-gem')
30
+ gem_home = File.expand_path(gem_home)
31
+
32
+ set_env('GEM_HOME', gem_home)
33
+ set_env('GEM_PATH', gem_home)
34
+ set_env('BUNDLE_PATH', gem_home)
35
+ unset_bundler_env_vars
36
+
37
+ paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
38
+ paths.unshift(File.join(gem_home, 'bin'))
39
+ set_env('PATH', paths.uniq.join(File::PATH_SEPARATOR))
40
+
41
+ return gem_home
42
+ end
43
+
44
+ def mkgemdir(gem_home)
45
+ # We don't need to removing existing directory in order to
46
+ # avoid redownload all dependecies for gem.
47
+ FileUtils::mkdir_p(gem_home) unless Dir.exist?(gem_home)
48
+ end
49
+
50
+ def gem_install(gemspec)
51
+ gem_file = nil
52
+ begin
53
+ pwd = Dir.pwd
54
+ gemspec_dir = File.dirname(gemspec)
55
+ Dir.chdir(gemspec_dir)
56
+ print 'Building gem... ' if @verbose
57
+ output = `gem build #{File.basename(gemspec)}`
58
+ puts 'done.'
59
+ Dir.chdir(pwd)
60
+
61
+ if $?.exitstatus != 0 then
62
+ raise "unable to build gem: #{output}"
63
+ end
64
+
65
+ if output =~ /File:\s+([A-Za-z0-9_.-]+[.]gem)/ then
66
+ gem_file = $1
67
+ print 'Installing gem... ' if @verbose
68
+ output = `gem install #{File.join(gemspec_dir, gem_file)}`
69
+ if $?.exitstatus != 0 then
70
+ raise "unable to install gem: #{output}"
71
+ end
72
+ puts 'done.' if @verbose
73
+ else
74
+ raise "garbled gem build output: #{output}"
75
+ end
76
+ ensure
77
+ if gem_file then
78
+ FileUtils.rm_f(File.join(gemspec_dir, gem_file))
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ # Include useful steps.
2
+ # See full list at https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber.rb
3
+ require 'aruba/cucumber'
4
+
5
+ # Include aruba api for own steps
6
+ # See https://github.com/cucumber/aruba/blob/master/lib/aruba/api.rb for more information
7
+ require 'aruba/api'
8
+
9
+ # Making test project and start server on it
10
+ require 'childprocess'
11
+ FileUtils::mkdir_p('tmp/sandbox')
12
+ server_process = nil
13
+ Dir.chdir('tmp/sandbox') do
14
+ FileUtils::rm_rf('servertesting')
15
+ # Create new project. TODO: think what if tau projecter not works correctly
16
+ ChildProcess.build('tau new servertesting').start.wait
17
+
18
+ # Run server on test project directory
19
+ Dir.chdir('servertesting') do
20
+ server_process = ChildProcess.build('tau server')
21
+ server_process.start
22
+ end
23
+ end
24
+
25
+ SANDBOX_PROJECT_DIR = File.expand_path('tmp/sandbox/servertesting')
26
+
27
+ at_exit do
28
+ server_process.stop
29
+ end
30
+
31
+ # Prepare test environment.
32
+ # Build and intall our gem.
33
+ # `tau something` command will be executed in test environment.
34
+ require File.expand_path("#{File.dirname(__FILE__)}/cukegem.rb")
35
+ CukeGem.setup('tau.gemspec')
data/lib/tau.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "tau/version"
2
+
3
+ module Tau
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,30 @@
1
+ module Tau
2
+ class Projecter
3
+ def self.new_project(directory, project_name)
4
+ Dir.chdir(directory)
5
+
6
+ raise "This already is the project directory" if project_dir?(directory)
7
+ raise "Wrong project name" unless project_name =~ /^\w+$/
8
+ raise "Directory exists" if Dir.exist?(project_name)
9
+
10
+ Dir.mkdir(project_name)
11
+ Dir.chdir(project_name) do
12
+ puts("\tcreate\tcode")
13
+ Dir.mkdir('code')
14
+ puts("\tcreate\tcode/js")
15
+ Dir.mkdir('code/js')
16
+ puts("\tcreate\tcode/css")
17
+ Dir.mkdir('code/css')
18
+ puts("\tcreate\tcode/img")
19
+ Dir.mkdir('code/img')
20
+ puts("\tcreate\ttau.yaml")
21
+ File.new('tau.yaml', 'w')
22
+ end
23
+ end
24
+
25
+ def self.project_dir?(directory)
26
+ Dir.chdir(directory)
27
+ Dir.exist?('code') and File.exist?('tau.yaml')
28
+ end
29
+ end
30
+ end
data/lib/tau/server.rb ADDED
@@ -0,0 +1,55 @@
1
+ require 'sinatra/base'
2
+ require 'haml'
3
+ require 'coffee-script'
4
+ require 'sass'
5
+
6
+ module Tau
7
+ class Server < Sinatra::Base
8
+ def self.start
9
+ set :port, 15000 # TODO: it should be changeable
10
+
11
+ # TODO: / route should return list of all files
12
+ get '/' do
13
+ "There should be list of all files."
14
+ end
15
+
16
+ # html
17
+ get /([\/\.\w-]+)\.html/ do |filename|
18
+ filename = "code/#{filename}"
19
+ return haml File.read("#{filename}.haml") if File.exist?("#{filename}.haml")
20
+ send_file "#{filename}.html" if File.exist?("#{filename}.html")
21
+ raise Sinatra::NotFound
22
+ end
23
+
24
+ # javascript
25
+ get /js\/([\/\.\w-]+)\.js/ do |filename|
26
+ filename = "code/js/#{filename}"
27
+ return coffee File.read("#{filename}.coffee") if File.exist?("#{filename}.coffee")
28
+ send_file "#{filename}.js" if File.exist?("#{filename}.js")
29
+ raise Sinatra::NotFound
30
+ end
31
+
32
+ # css
33
+ get /css\/([\/\.\w-]+)\.css/ do |filename|
34
+ filename = "code/css/#{filename}"
35
+ return sass File.read("#{filename}.sass") if File.exist?("#{filename}.sass")
36
+ return scss File.read("#{filename}.scss") if File.exist?("#{filename}.scss")
37
+ send_file "#{filename}.css" if File.exist?("#{filename}.css")
38
+ raise Sinatra::NotFound
39
+ end
40
+
41
+ # images
42
+ get /img\/([\/\.\w-]+)/ do |filename|
43
+ filename = "code/img/#{filename}"
44
+ send_file filename if File.exist?(filename)
45
+ raise Sinatra::NotFound
46
+ end
47
+
48
+ not_found do
49
+ "No such file or directory"
50
+ end
51
+
52
+ run!
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module Tau
2
+ VERSION = "0.0.1"
3
+ end
data/tau.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tau/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tau"
7
+ s.version = Tau::VERSION
8
+ s.authors = ["Dmitry Zhlobo"]
9
+ s.email = ["dima.zhlobo@gmail.com"]
10
+ s.homepage = "http://github.com/proghat/tau"
11
+ s.summary = %q{Tool for web designers want to use haml, sass, coffee-script and others.}
12
+ s.description = %q{tau provide you write web pages on haml, stylesheets on sass and scripts on coffee.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ ['cucumber', 'aruba', 'childprocess'].each do |dependecy|
20
+ s.add_development_dependency dependecy
21
+ end
22
+
23
+ ['sinatra', 'sass', 'coffee-script', 'haml'].each do |dependecy|
24
+ s.add_dependency dependecy
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tau
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmitry Zhlobo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: &13643180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *13643180
25
+ - !ruby/object:Gem::Dependency
26
+ name: aruba
27
+ requirement: &13641560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *13641560
36
+ - !ruby/object:Gem::Dependency
37
+ name: childprocess
38
+ requirement: &13640800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *13640800
47
+ - !ruby/object:Gem::Dependency
48
+ name: sinatra
49
+ requirement: &13702480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *13702480
58
+ - !ruby/object:Gem::Dependency
59
+ name: sass
60
+ requirement: &13701880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *13701880
69
+ - !ruby/object:Gem::Dependency
70
+ name: coffee-script
71
+ requirement: &13701240 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *13701240
80
+ - !ruby/object:Gem::Dependency
81
+ name: haml
82
+ requirement: &13700140 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *13700140
91
+ description: tau provide you write web pages on haml, stylesheets on sass and scripts
92
+ on coffee.
93
+ email:
94
+ - dima.zhlobo@gmail.com
95
+ executables:
96
+ - tau
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - .gitignore
101
+ - Gemfile
102
+ - README.md
103
+ - Rakefile
104
+ - bin/tau
105
+ - features/making_projects.feature
106
+ - features/server.feature
107
+ - features/step_definitions/fs.rb
108
+ - features/step_definitions/network.rb
109
+ - features/support/cukegem.rb
110
+ - features/support/env.rb
111
+ - lib/tau.rb
112
+ - lib/tau/projecter.rb
113
+ - lib/tau/server.rb
114
+ - lib/tau/version.rb
115
+ - tau.gemspec
116
+ homepage: http://github.com/proghat/tau
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.15
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Tool for web designers want to use haml, sass, coffee-script and others.
140
+ test_files:
141
+ - features/making_projects.feature
142
+ - features/server.feature
143
+ - features/step_definitions/fs.rb
144
+ - features/step_definitions/network.rb
145
+ - features/support/cukegem.rb
146
+ - features/support/env.rb