fangorn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc59e74e0194981fccfa496e26e9c22b3476477f
4
+ data.tar.gz: b7679609342ff1d2e38bbaa65eec33ac022c3df2
5
+ SHA512:
6
+ metadata.gz: 9b14b6e5adadaf5ea4bfc504074da7192bad86b2461cdb82a38ad7e8c079bc14d1ba9386a34d76901a4ae48679dfcaf97360502ef38977045697d1608f76ebde
7
+ data.tar.gz: f1389a89d8e2ce3eb5662bccc23eaf3d92294cfea254886effd0856e1be30befb0fb17c73962ae282427f4c3ca89c96b9a6e293b25c1e2866468d952b571b6b9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ryan Calhoun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # fangorn
2
+ Asset compiler for haml + sass + javascript, and a local development server
3
+
4
+ Currently an early WIP.
data/bin/fangorn ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ gem 'emplace'
6
+ rescue LoadError
7
+ end
8
+
9
+ require 'fangorn/app'
10
+ Fangorn::App.new.run
@@ -0,0 +1,98 @@
1
+ require 'listen'
2
+ require 'optparse'
3
+ require 'webrick'
4
+
5
+ require_relative 'output'
6
+
7
+ module Fangorn
8
+ class App
9
+ def run
10
+ options = OptionParser.new do |opts|
11
+ opts.on('-s', '--serve', 'Watch source files for change, and serve compiled results') do
12
+ @serve = true
13
+ end
14
+ opts.on('-Jsrc=dest', 'Add javascript vendor directory') do |arg|
15
+ if m = /^(.*?)\/?=(.*?)\/?$/.match(arg)
16
+ Haml::SCRIPT_SOURCES[m[1]] = m[2]
17
+ end
18
+ end
19
+ end
20
+
21
+ begin
22
+ options.parse! ARGV
23
+ rescue OptionParser::ParseError => e
24
+ STDERR.puts e
25
+ puts options
26
+ exit 1
27
+ end
28
+
29
+ if @serve
30
+ puts "Watching #{Output::source}"
31
+ listener = Listen.to(Output::source, :filter => /\.(haml|sass|js|ico)$/, &update)
32
+ listener.start
33
+
34
+ puts 'Starting server on port 8080'
35
+ server = WEBrick::HTTPServer.new Port: 8080
36
+ server.mount '/', NoCacheFileHandler, Output::dest
37
+ trap('INT') { server.stop }
38
+ server.start
39
+ else
40
+ puts "Updating #{Output::source}"
41
+ update[Dir[File.join(Output::source, '**/*.{haml,sass,js,ico}')], [], []]
42
+ end
43
+ end
44
+ def report(type, input, output)
45
+ puts <<-eos
46
+ #{File.extname(output.to_s).upcase} #{type} @ #{Time.now.strftime("%F %T")}:
47
+ - from: #{input}
48
+ - to: #{output}
49
+ eos
50
+ end
51
+
52
+ def update
53
+ ->(modified, added, removed) do
54
+ unless added.select {|m| m =~ /\.(js|sass)$/}.empty?
55
+ modified += Dir[File.join(Output::source, '**/*.haml')]
56
+ end
57
+
58
+ ordered(modified + added).each do |input|
59
+ if output = Output.make(input)
60
+ output.create!
61
+ report 'generated', input, output
62
+ end
63
+ end
64
+
65
+ ordered(removed).each do |input|
66
+ if output = Output.make(input)
67
+ output.remove!
68
+ report 'removed', input, output
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+ def of_type(type)
76
+ ->(f) { File.extname(f) == type }
77
+ end
78
+
79
+ def ordered(files)
80
+ files = files.sort_by(&:length)
81
+
82
+ sass = files.select &of_type('.sass')
83
+ js = files.select &of_type('.js')
84
+ haml = files.select &of_type('.haml')
85
+
86
+ (sass + js + haml + files).uniq
87
+ end
88
+ end
89
+ class NoCacheFileHandler < WEBrick::HTTPServlet::FileHandler
90
+ def do_GET(req, res)
91
+ super
92
+ res['Cache-Control'] = 'no-cache'
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+
@@ -0,0 +1,50 @@
1
+ require 'haml'
2
+
3
+ module Fangorn
4
+ class Haml < Output
5
+ ::Haml::Options.defaults[:format] = :html5
6
+
7
+ SCRIPT_SOURCES = {}
8
+
9
+ def initialize(input)
10
+ super input, File.join(Output::dest, input.sub(File.join(Output::source, ''), '').sub(/\.haml$/, ''))
11
+ end
12
+
13
+ protected
14
+ def create_command
15
+ File.open(@output, 'w') do |f|
16
+ f.write ::Haml::Engine.new(File.read(@input)).render self
17
+ end
18
+ end
19
+
20
+ def css_include(file)
21
+ ::Haml::Engine.new("%link{ rel: 'stylesheet', type: 'text/css', href: '#{file}' }").render
22
+ end
23
+
24
+ def css_include_tree(dir)
25
+ Dir[File.join(Output::dest, dir, '**', '*.css')].map do |file|
26
+ css_include file.sub File.join(Output::dest, ''), ''
27
+ end.join
28
+ end
29
+
30
+ def js_include(file)
31
+ SCRIPT_SOURCES.each do |refdir, sourcedir|
32
+ src = file.sub /^#{refdir}\//, "#{sourcedir}/"
33
+ if File.exists? src
34
+ out = File.join(Output::dest, file)
35
+ FileUtils.mkdir_p File.dirname(out)
36
+ File.open(out, 'w') do |f|
37
+ f.write File.read(src)
38
+ end
39
+ break
40
+ end
41
+ end
42
+ ::Haml::Engine.new("%script{ src: '#{file}' }").render
43
+ end
44
+ def js_include_tree(dir)
45
+ Dir[File.join(Output::dest, dir, '**', '*.js')].sort_by(&:length).map do |file|
46
+ js_include file.sub File.join(Output::dest, ''), ''
47
+ end.join
48
+ end
49
+ end
50
+ end
data/lib/fangorn/js.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Fangorn
2
+ class Js < Output
3
+ APPLICATION_JS = File.join Output::dest, 'js', 'application.js'
4
+ @@cleaned = false
5
+
6
+ def initialize(input)
7
+ output = Output::dist? ? APPLICATION_JS : File.join(Output::dest?, input.sub(File.join(Output::source, ''), ''))
8
+ super input, output
9
+ end
10
+
11
+ protected
12
+ def create_command
13
+ remove! unless @@cleaned
14
+ @@cleaned = true
15
+
16
+ File.open(@output, Output::dist? ? 'a' : 'w') do |f|
17
+ f.puts "// #{@input}" if Output::dist?
18
+ f.write File.read(@input)
19
+ f.puts if Output::dist?
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,60 @@
1
+ require 'fileutils'
2
+
3
+ module Fangorn
4
+ class Output
5
+ def initialize(input, output)
6
+ @input, @output = input, output
7
+ end
8
+ def create!
9
+ FileUtils.mkdir_p File.dirname(@output)
10
+ create_command
11
+ end
12
+ def remove!
13
+ FileUtils.rm_f @output
14
+ end
15
+ def to_s
16
+ @output
17
+ end
18
+ def self.make(input)
19
+ type = File.extname(input)[1..-1]
20
+ begin
21
+ Fangorn.const_get(type.capitalize).new input
22
+ rescue LoadError, NameError
23
+ StaticFile.new input
24
+ end
25
+ end
26
+
27
+ def self.dist?
28
+ @@dist
29
+ end
30
+
31
+ def self.source
32
+ @@source
33
+ end
34
+
35
+ def self.dest
36
+ @@dest
37
+ end
38
+
39
+ def self.dist!
40
+ @@dist = true
41
+ end
42
+
43
+ def self.source= (source)
44
+ @@source = source
45
+ end
46
+
47
+ def self.dest= (dest)
48
+ @@dest = dest
49
+ end
50
+
51
+ @@dist = false
52
+ @@source = 'app'
53
+ @@dest = 'public'
54
+ end
55
+ end
56
+
57
+ require_relative 'haml'
58
+ require_relative 'sass'
59
+ require_relative 'js'
60
+ require_relative 'static_file'
@@ -0,0 +1,25 @@
1
+ require 'sass'
2
+
3
+ module Fangorn
4
+ class Sass < Output
5
+ APPLICATION_CSS = File.join Output::dest, 'stylesheets', 'application.css'
6
+ @@cleaned = false
7
+
8
+ def initialize(input)
9
+ output = Output::dist? ? APPLICATION_CSS : File.join(Output::dest, input.sub(File.join(Output::source, ''), '')).sub(/sass$/, 'css')
10
+ super input, output
11
+ end
12
+
13
+ protected
14
+ def create_command
15
+ remove! unless @@cleaned
16
+ @@cleaned = true
17
+
18
+ File.open(@output, Output::dist? ? 'a' : 'w') do |f|
19
+ f.puts "/* #{@input} */"
20
+ f.write ::Sass::Engine.new(File.read(@input)).render
21
+ f.puts
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+
3
+ module Fangorn
4
+ class StaticFile < Output
5
+ def initialize(input)
6
+ output = File.join(Output::dest, input.sub(File.join(Output::source, ''), ''))
7
+ super input, output
8
+ end
9
+
10
+ protected
11
+ def create_command
12
+ FileUtils.cp @input, @output
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fangorn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Calhoun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Asset compiler for front-end assets.
14
+ email:
15
+ - ryanjamescalhoun@gmail.com
16
+ executables:
17
+ - fangorn
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/fangorn
24
+ - lib/fangorn/app.rb
25
+ - lib/fangorn/haml.rb
26
+ - lib/fangorn/js.rb
27
+ - lib/fangorn/output.rb
28
+ - lib/fangorn/sass.rb
29
+ - lib/fangorn/static_file.rb
30
+ homepage: https://github.com/ryancalhoun/fangorn
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.5.1
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: Haml + Sass + Javascript
54
+ test_files: []