staticz 1.0.0

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
+ SHA256:
3
+ metadata.gz: a2af4249d3a8034c01106d418ff80cd9aed8ba55570c73a3d720753f93068f62
4
+ data.tar.gz: 7388337b33da4d05efd3bec20513b5c5c37938db76dc4867c3c5005dc8572e4a
5
+ SHA512:
6
+ metadata.gz: b874bbde2ae61190e2cadc2e810036eb13f5321cd8427063948879dfa064683842340fcd3753bdb788f5fe499b73d5a15f07c73681206315c95c94fed1c6e265
7
+ data.tar.gz: 5576cfc9c86cc8d3e2456f653c2b744dfc10f4e1c4a4e23917227a2e2d432c2c9161738fbf9ae828aa75b6b82c417fb6b5be673e5b259777af666851d34ef200
data/bin/staticz ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'staticz'
3
+
4
+ Staticz::init
data/lib/builder.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "haml"
2
+
3
+ module Staticz
4
+ class Builder
5
+ def initialize
6
+ build
7
+ end
8
+
9
+ private
10
+
11
+ def build
12
+ Dir.mkdir('build') unless File.exist?('build')
13
+
14
+ Staticz::Manifest.instance.build
15
+ end
16
+ end
17
+ end
data/lib/colors.rb ADDED
@@ -0,0 +1,9 @@
1
+ class Colors
2
+ def self.in_red(text)
3
+ "\e[31m#{text}\e[0m"
4
+ end
5
+
6
+ def self.in_green(text)
7
+ "\e[32m#{text}\e[0m"
8
+ end
9
+ end
data/lib/helpers.rb ADDED
@@ -0,0 +1,26 @@
1
+ def render(component, &block)
2
+ engine = ::Haml::Engine.new(File.read("src/#{component}.haml"))
3
+
4
+ if block
5
+ engine.render({}, &block)
6
+ else
7
+ engine.render
8
+ end
9
+ end
10
+
11
+ def link(path, text: nil, &block)
12
+ if block
13
+ content = capture_haml(&block)
14
+ "<a href=\"#{path}\">#{content}</a>"
15
+ else
16
+ "<a href=\"#{path}\">#{text}</a>"
17
+ end
18
+ end
19
+
20
+ def stylesheet(path)
21
+ "<link href=\"#{path}\" rel=\"stylesheet\">"
22
+ end
23
+
24
+ def javascript(path)
25
+ "<script src=\"#{path}\"></script>"
26
+ end
@@ -0,0 +1,40 @@
1
+ module Staticz
2
+ module Compilable
3
+ def path
4
+ name.to_s
5
+ end
6
+
7
+ def source_path
8
+ "src/#{name}.#{source_file_ending}"
9
+ end
10
+
11
+ def build_path
12
+ "build/#{name}.#{build_file_ending}"
13
+ end
14
+
15
+ def exists?
16
+ File.exist? source_path
17
+ end
18
+
19
+ def path_method_name
20
+ "#{path.gsub(/[\/-]/, "_")}_path"
21
+ end
22
+
23
+ def valid
24
+ if exists?
25
+ Colors.in_green("✔")
26
+ else
27
+ Colors.in_red("✘ (file does not exist)")
28
+ end
29
+ end
30
+
31
+ def create_link_function
32
+ link_path = "#{name}.#{build_file_ending}"
33
+ Object.send(:define_method, path_method_name) { link_path }
34
+ end
35
+
36
+ def print(indentation)
37
+ puts "#{" " * (indentation * 3)}└─ #{tile_type_name}: #{path} #{valid} -> #{path_method_name}"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ require 'coffee-script'
2
+
3
+ module Staticz
4
+ class Cs
5
+ include Compilable
6
+
7
+ attr_reader :name
8
+
9
+ def source_file_ending = "coffee"
10
+
11
+ def build_file_ending = "js"
12
+
13
+ def tile_type_name = "Coff"
14
+
15
+ def initialize(name)
16
+ @name = name
17
+ end
18
+
19
+ def build
20
+ if exists?
21
+ js = CoffeeScript.compile File.read(source_path)
22
+
23
+ File.write build_path, js
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module Staticz
2
+ class Haml
3
+ include Compilable
4
+
5
+ attr_reader :name
6
+
7
+ def source_file_ending = "haml"
8
+
9
+ def build_file_ending = "html"
10
+
11
+ def tile_type_name = "Haml"
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ def build
18
+ if exists?
19
+ engine = ::Haml::Engine.new(File.read(source_path))
20
+
21
+ File.write build_path, engine.render
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Staticz
2
+ class Js
3
+ include Compilable
4
+
5
+ attr_reader :name
6
+
7
+ def source_file_ending = "js"
8
+
9
+ def build_file_ending = "js"
10
+
11
+ def tile_type_name = "Js"
12
+
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+
17
+ def build
18
+ if exists?
19
+ File.write build_path, File.read(source_path)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,77 @@
1
+ require 'singleton'
2
+ require_relative 'compilable'
3
+ require_relative 'sub'
4
+ require_relative 'haml'
5
+ require_relative 'sass'
6
+ require_relative 'scss'
7
+ require_relative 'js'
8
+ require_relative 'cs'
9
+
10
+ module Staticz
11
+ class Manifest
12
+ include Singleton
13
+
14
+ attr_reader :elements
15
+
16
+ def initialize
17
+ @elements = []
18
+ end
19
+
20
+ def sub(name, &block)
21
+ s = Staticz::Sub.new(name)
22
+ elements.push(s)
23
+
24
+ s.instance_eval(&block)
25
+ end
26
+
27
+ def haml(name)
28
+ elements.push(Staticz::Haml.new(name))
29
+ end
30
+
31
+ def sass(name)
32
+ elements.push(Staticz::Sass.new(name))
33
+ end
34
+
35
+ def scss(name)
36
+ elements.push(Staticz::Scss.new(name))
37
+ end
38
+
39
+ def js(name)
40
+ elements.push(Staticz::Js.new(name))
41
+ end
42
+
43
+ def coffee(name)
44
+ elements.push(Staticz::Cs.new(name))
45
+ end
46
+
47
+ def build
48
+ load "#{Dir.pwd}/manifest.rb"
49
+
50
+ elements.each do |e|
51
+ e.create_link_function
52
+ end
53
+
54
+ elements.each do |e|
55
+ e.build
56
+ end
57
+
58
+ print
59
+ end
60
+
61
+ def self.define(&block)
62
+ Staticz::Manifest.instance.define(block)
63
+ end
64
+
65
+ def define(block)
66
+ elements.clear
67
+ instance_eval(&block)
68
+ end
69
+
70
+ def print
71
+ puts "Manifest:"
72
+ elements.each do |e|
73
+ e.print(0)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,27 @@
1
+ require 'sassc'
2
+
3
+ module Staticz
4
+ class Sass
5
+ include Compilable
6
+
7
+ attr_reader :name
8
+
9
+ def source_file_ending = "sass"
10
+
11
+ def build_file_ending = "css"
12
+
13
+ def tile_type_name = "Sass"
14
+
15
+ def initialize(name)
16
+ @name = name
17
+ end
18
+
19
+ def build
20
+ if exists?
21
+ engine = ::SassC::Engine.new(File.read(source_path), syntax: :sass, style: :compressed)
22
+
23
+ File.write build_path, engine.render
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'sassc'
2
+
3
+ module Staticz
4
+ class Scss
5
+ include Compilable
6
+
7
+ attr_reader :name
8
+
9
+ def source_file_ending = "scss"
10
+
11
+ def build_file_ending = "css"
12
+
13
+ def tile_type_name = "Scss"
14
+
15
+ def initialize(name)
16
+ @name = name
17
+ end
18
+
19
+ def build
20
+ if exists?
21
+ engine = ::SassC::Engine.new(File.read(source_path), syntax: :scss, style: :compressed)
22
+
23
+ File.write build_path, engine.render
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ module Staticz
2
+ class Sub
3
+ attr_reader :name, :elements
4
+
5
+ def initialize(name)
6
+ @name = name
7
+ @elements = []
8
+ end
9
+
10
+ def sub(name, &block)
11
+ s = Staticz::Sub.new("#{@name}/#{name}")
12
+ elements.push(s)
13
+ s.instance_eval(&block)
14
+ end
15
+
16
+ def haml(name, &block)
17
+ elements.push(Staticz::Haml.new("#{@name}/#{name}"))
18
+ end
19
+
20
+ def sass(name, &block)
21
+ elements.push(Staticz::Sass.new("#{@name}/#{name}"))
22
+ end
23
+
24
+ def scss(name, &block)
25
+ elements.push(Staticz::Scss.new("#{@name}/#{name}"))
26
+ end
27
+
28
+ def js(name, &block)
29
+ elements.push(Staticz::Js.new("#{@name}/#{name}"))
30
+ end
31
+
32
+ def coffee(name, &block)
33
+ elements.push(Staticz::Cs.new("#{@name}/#{name}"))
34
+ end
35
+
36
+ def build
37
+ Dir.mkdir("build/#{name}") if !Dir.exist?("build/#{name}")
38
+
39
+ elements.each do |e|
40
+ e.build
41
+ end
42
+ end
43
+
44
+ def create_link_function
45
+ elements.each do |e|
46
+ e.create_link_function
47
+ end
48
+ end
49
+
50
+ def print(indentation)
51
+ puts "#{" " * (indentation * 3)}└─ Sub: #{name}"
52
+ elements.each do |e|
53
+ e.print(indentation + 1)
54
+ end
55
+ end
56
+
57
+ def path
58
+ "src/#{name}"
59
+ end
60
+ end
61
+ end
data/lib/server.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'thin'
2
+ require 'listen'
3
+
4
+ module Staticz
5
+ class Server
6
+ def initialize
7
+ puts "Starting server..."
8
+
9
+ app = Rack::Builder.new do
10
+ map "/" do
11
+ run Rack::Directory.new("build")
12
+ end
13
+ end
14
+
15
+ thin_server = Thin::Server.new '127.0.0.1', 3000
16
+ thin_server.app = app
17
+
18
+ puts "Building..."
19
+ Staticz::Builder.new
20
+
21
+ Thread.new { listen_to_file_changes }
22
+ thin_server.start
23
+ end
24
+
25
+ private
26
+
27
+ def listen_to_file_changes
28
+ listener = Listen.to('src') do |modified, added, removed|
29
+ file_names = (modified + added + removed)
30
+ .map do |file|
31
+ file.gsub "#{Dir.pwd}/src/", ""
32
+ end
33
+ .join(", ")
34
+
35
+ puts "#{file_names} changed, rebuilding..."
36
+ Builder.new
37
+ puts "Rebuilding successful"
38
+ end
39
+ listener.start
40
+ end
41
+ end
42
+ end
data/lib/staticz.rb ADDED
@@ -0,0 +1,37 @@
1
+ require_relative 'manifest/manifest'
2
+ require_relative 'template'
3
+ require_relative 'server'
4
+ require_relative 'builder'
5
+ require_relative 'helpers'
6
+ require_relative 'colors'
7
+
8
+ module Staticz
9
+ def self.init
10
+ usage = [
11
+ "Usage: staticz <mode>",
12
+ "",
13
+ " new [name]",
14
+ " server",
15
+ " manifest",
16
+ " build"
17
+ ].join("\n")
18
+
19
+ case ARGV[0]
20
+ when 'new'
21
+ if ARGV[1]
22
+ Staticz::Template.new(ARGV[1])
23
+ else
24
+ puts usage
25
+ end
26
+ when 'server'
27
+ Staticz::Server.new
28
+ when 'manifest'
29
+ load "#{Dir.pwd}/manifest.rb"
30
+ Staticz::Manifest.instance.print
31
+ when 'build'
32
+ Staticz::Builder.new
33
+ else
34
+ puts usage
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ Staticz::Manifest.define do
2
+ haml :index
3
+
4
+ sub :css do
5
+ sass :main
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ html,body
2
+ padding: 0
3
+ margin: 0
@@ -0,0 +1 @@
1
+ %footer
@@ -0,0 +1,2 @@
1
+ = render :template do
2
+ %main
@@ -0,0 +1 @@
1
+ %nav
@@ -0,0 +1,21 @@
1
+ !!! 5
2
+ %html
3
+ %head
4
+ %title App created with staticz
5
+
6
+ %meta{name: "description", content: "Site description"}
7
+ %meta{name: "keywords", content: "website, staticz"}
8
+ %meta{name: "viewport", content: "width=device-width, initial-scale=1"}
9
+
10
+ %meta{property: "og:site_name", content: "example.com"}
11
+ %meta{property: "og:title", content: "Site created with staticz"}
12
+ %meta{property: "og:description", content: "Site description"}
13
+ %meta{property: "og:type", content: "website"}
14
+ %meta{property: "og:url", content: "https://example.com/"}
15
+ %meta{property: "og:title", content: "App created with staticz"}
16
+
17
+ = stylesheet css_main_path
18
+ %body
19
+ = render :nav
20
+ = capture_haml(&block)
21
+ = render :footer
data/lib/template.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Staticz
2
+ class Template
3
+ def initialize(name)
4
+ src = File.join(File.dirname(__FILE__), "template")
5
+
6
+ FileUtils.copy_entry src, File.join(Dir.pwd, name)
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: staticz
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Philipp Schlesinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: haml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: listen
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sassc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coffee-script
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.4'
97
+ description: Create websites with haml and sass, and compile them into static html
98
+ and css
99
+ email:
100
+ - info@philcomm.dev
101
+ executables:
102
+ - staticz
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - bin/staticz
107
+ - lib/builder.rb
108
+ - lib/colors.rb
109
+ - lib/helpers.rb
110
+ - lib/manifest/compilable.rb
111
+ - lib/manifest/cs.rb
112
+ - lib/manifest/haml.rb
113
+ - lib/manifest/js.rb
114
+ - lib/manifest/manifest.rb
115
+ - lib/manifest/sass.rb
116
+ - lib/manifest/scss.rb
117
+ - lib/manifest/sub.rb
118
+ - lib/server.rb
119
+ - lib/staticz.rb
120
+ - lib/template.rb
121
+ - lib/template/manifest.rb
122
+ - lib/template/src/css/main.sass
123
+ - lib/template/src/footer.haml
124
+ - lib/template/src/index.haml
125
+ - lib/template/src/nav.haml
126
+ - lib/template/src/template.haml
127
+ homepage: http://rubygems.org/gems/staticz
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.3.3
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Static website compiler
150
+ test_files: []