zepto 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8aab4839dfa78673ccdc08be29310993699f9313973b26f74724ec3e6cb3c7b6
4
+ data.tar.gz: 5a2f994e9b16d71a5bb2ea7cc4c6b329b347d9b559eadff6b30bf47db1a7358b
5
+ SHA512:
6
+ metadata.gz: a4e530310922a2650d429e0bba2b538b2fad1e1c1939bfba62099875bea5a4f8a75bcc2d8485a419b896aff1dc941ed22a6d850039ef813c404f39e1692581f3
7
+ data.tar.gz: d8da739a195af8f24916df3274532622d7f022724eff57992bf9609a752f1c927038e049e94901916bca0d4e1891e3abf4938fb2090e0f1539785c1743f9bf67
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "zepto"
4
+
5
+ default_config = {
6
+ "assets": "_assets",
7
+ "layout": "_layout",
8
+ "styles": "_styles",
9
+ "javascript": "_javascript",
10
+ }
11
+
12
+ config = default_config
13
+ config_file_path = "zepto.json"
14
+
15
+ # Read user config file if present and merge it with default config
16
+ if File.file?(config_file_path)
17
+ config_file = File.open(config_file_path)
18
+ user_config = JSON.load config_file
19
+ config = config.merge(Hash[user_config.map { |k, v| [k.to_sym, v] }])
20
+ end
21
+
22
+ case ARGV[0]
23
+ when "serve"
24
+ Zepto.new(config).serve
25
+ when "build"
26
+ Zepto.new(config).build
27
+ when "help"
28
+ puts %(
29
+ zepto serve: To serve the files locally in dev mode
30
+ zepto build: Building for production
31
+ zepto help: Help options
32
+
33
+ For more details visit https://github.com/Rafi993/zepto
34
+ )
35
+ else
36
+ puts "I don't understand the command. Try running 'zepto help'"
37
+ end
@@ -0,0 +1,40 @@
1
+ require "uglifier"
2
+
3
+ class Javascript
4
+ def initialize(javascript_path)
5
+ @javascript_path = javascript_path
6
+ @javascript = {}
7
+ end
8
+
9
+ def read(path)
10
+ if File.file? path
11
+ return File.read(path)
12
+ else
13
+ raise "File #{path} does not exist"
14
+ end
15
+ end
16
+
17
+ def parse(path)
18
+ file_content = read path
19
+ return file_content
20
+ end
21
+
22
+ def minify(content)
23
+ return Uglifier.compile(content, harmony: true)
24
+ end
25
+
26
+ def walk()
27
+ for file in Dir[@javascript_path + "/**/*.js"]
28
+ @javascript[file.sub(@javascript_path + "/", "").sub(".js", "").to_sym] = minify(parse(file))
29
+ end
30
+ end
31
+
32
+ def compile()
33
+ walk
34
+ @javascript.each do |key, content|
35
+ view_path = Pathname("dist/" + key.to_s.delete_prefix('"').delete_suffix('/"') + ".js")
36
+ view_path.dirname.mkpath
37
+ view_path.write(content)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,117 @@
1
+ require "redcarpet"
2
+ require "set"
3
+
4
+ require_relative "./template.rb"
5
+
6
+ class Markup
7
+ def initialize(layout_path)
8
+ @content = {}
9
+ @templates = {}
10
+ @tags = Set.new
11
+ @layout_path = layout_path
12
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true,
13
+ strikethrough: true, highlight: true,
14
+ superscript: true)
15
+ end
16
+
17
+ def read(path)
18
+ if File.file? path
19
+ return File.read(path)
20
+ else
21
+ raise "File #{path} does not exist"
22
+ end
23
+ end
24
+
25
+ def parse_markdown(path)
26
+ file_content = read path
27
+
28
+ header = file_content.match(/-{3,}(.+)-{3,}/m)
29
+ post = {}
30
+ post[:path] = path.sub("content/", "").sub(".md", "")
31
+
32
+ if header
33
+ header_data = header.captures[0].split("\n").reject! { |s| s.nil? || s.strip.empty? }
34
+
35
+ for header in header_data
36
+ key, value = header.split(":", 2)
37
+ post[key.strip.to_sym] = value.strip.delete_prefix('"').delete_suffix('"')
38
+ end
39
+ end
40
+
41
+ post[:content] = @markdown.render(file_content.gsub(/-{3,}(.+)-{3,}/m, ""))
42
+
43
+ tags = Set.new
44
+ # Converting tags to Set
45
+ if post.has_key? :tags
46
+ for tag in post[:tags].to_s.delete_prefix("[").delete_suffix("]").split(/,/)
47
+ tag_name = tag.strip.delete_prefix('"').delete_suffix('"').strip
48
+ tags.add(tag_name)
49
+ # Storing all tags in @tags
50
+ @tags.add(tag_name)
51
+ end
52
+ end
53
+ post[:tags] = tags
54
+
55
+ return post
56
+ end
57
+
58
+ def walk()
59
+ for file in Dir["content/**/*.md"]
60
+ @content[file.sub("content/", "").sub(".md", "").to_sym] = parse_markdown(file)
61
+ end
62
+ end
63
+
64
+ def get_tags
65
+ return @tags
66
+ end
67
+
68
+ def get_tag(tag)
69
+ if @tags.include?(tag)
70
+ content_with_tag = []
71
+ @content.each do |key, meta_data|
72
+ if meta_data[:tags].include?(tag)
73
+ content_with_tag.push(meta_data)
74
+ end
75
+ end
76
+ return content_with_tag
77
+ else
78
+ puts "You have not defined #{tag}"
79
+ return []
80
+ end
81
+ end
82
+
83
+ def get_path(path)
84
+ content_with_path = []
85
+ @content.each do |key, meta_data|
86
+ puts meta_data[:path]
87
+ if meta_data[:path].start_with?(path)
88
+ content_with_path.push(meta_data)
89
+ end
90
+ end
91
+ return content_with_path
92
+ end
93
+
94
+ def compile()
95
+ walk
96
+ @content.each do |key, meta_data|
97
+ layout = (meta_data[:layout]).delete_prefix('"').delete_suffix('"')
98
+ if layout
99
+ layout_file_path = @layout_path + "/" + layout
100
+ if File.file?(layout_file_path)
101
+ template = File.read(layout_file_path)
102
+ path = meta_data[:path]
103
+ # TODO: Need cleanup way methods are passed
104
+ @templates[path] = Template.new(template, meta_data, method(:get_tag),
105
+ method(:get_tags),
106
+ method(:get_path))
107
+ @templates[path].render
108
+ @templates[path].write
109
+ else
110
+ raise "File #{layout_file_path} is not found"
111
+ end
112
+ else
113
+ raise "You have not specified any layout for #{key}"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,38 @@
1
+ class Styles
2
+ def initialize(styles_path)
3
+ @styles_path = styles_path
4
+ @styles = {}
5
+ end
6
+
7
+ def read(path)
8
+ if File.file? path
9
+ return File.read(path)
10
+ else
11
+ raise "File #{path} does not exist"
12
+ end
13
+ end
14
+
15
+ def parse(path)
16
+ file_content = read path
17
+ return file_content
18
+ end
19
+
20
+ def minify(content)
21
+ return content.gsub(/\s+/, "")
22
+ end
23
+
24
+ def walk()
25
+ for file in Dir[@styles_path + "/**/*.css"]
26
+ @styles[file.sub(@styles_path + "/", "").sub(".css", "").to_sym] = minify(parse(file))
27
+ end
28
+ end
29
+
30
+ def compile()
31
+ walk
32
+ @styles.each do |key, content|
33
+ view_path = Pathname("dist/" + key.to_s.delete_prefix('"').delete_suffix('/"') + ".css")
34
+ view_path.dirname.mkpath
35
+ view_path.write(content)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ require "erb"
2
+ require "pathname"
3
+
4
+ class Template
5
+ def initialize(template, meta_data, get_tag, get_tags, get_path)
6
+ @template = template
7
+ define_singleton_method(:get_tag) do |tag|
8
+ get_tag.call(tag)
9
+ end
10
+
11
+ define_singleton_method(:get_tags) do
12
+ get_tags.call
13
+ end
14
+
15
+ define_singleton_method(:get_path) do |path|
16
+ get_path.call(path)
17
+ end
18
+
19
+ # Setting all the metadata keys as instance variables
20
+ meta_data.each do |key, val|
21
+ instance_variable_set("@#{key}", val)
22
+ end
23
+ end
24
+
25
+ def render()
26
+ renderer = ERB.new(@template)
27
+ @html = renderer.result(binding)
28
+ end
29
+
30
+ def write
31
+ view_path = Pathname("dist/" + @path.delete_prefix('"').delete_suffix('"').delete_suffix("/") + ".html")
32
+ view_path.dirname.mkpath
33
+ view_path.write(@html)
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require_relative "./markup.rb"
2
+ require_relative "./styles.rb"
3
+ require_relative "./javascript.rb"
4
+
5
+ class Zepto
6
+ def initialize(config)
7
+ @assets_path = config[:assets]
8
+ @layout = config[:layout]
9
+ @styles_path = config[:styles]
10
+ @javascript_path = config[:javascript]
11
+ end
12
+
13
+ def serve
14
+ puts "Starting server in port 3000"
15
+ end
16
+
17
+ def build
18
+ puts "Building static files"
19
+
20
+ # Building Layouts
21
+ markup = Markup.new(@layout)
22
+ markup.compile()
23
+
24
+ # Building styles
25
+ styles = Styles.new(@styles_path)
26
+ styles.compile()
27
+
28
+ # Minifying js
29
+ javascript = Javascript.new(@javascript_path)
30
+ javascript.compile()
31
+
32
+ # Copying assets in to dist/
33
+ if File.directory? @assets_path
34
+ FileUtils.cp_r @assets_path + "/.", "dist"
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zepto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Rafi993
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple static site generator with battries included
14
+ email: rafi993@protonmail.com
15
+ executables:
16
+ - zepto
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/zepto
21
+ - lib/javascript.rb
22
+ - lib/markup.rb
23
+ - lib/styles.rb
24
+ - lib/template.rb
25
+ - lib/zepto.rb
26
+ homepage: https://github.com/Rafi993/zepto
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubygems_version: 3.1.2
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Simple static site generator
49
+ test_files: []