alister 1.0.0

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/lib/site.rb ADDED
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+
5
+ module Alister
6
+ # Main site builder use this to build your site
7
+ # @example A simple site
8
+ # s = Alister::Site.new
9
+ # s.route '/', pageroot_page
10
+ # s.route '/about/', pageabout_page
11
+ # s.build("./build")
12
+ #
13
+ # s.file '/main.css', scss_string
14
+ # s.build_and_reset("./build")
15
+ # s.assets do
16
+ # source "./assets"
17
+ # enable_webp_conversion unless DEBUG
18
+ # file "**/*"
19
+ # build_to_and_reset "./build/assets/"
20
+ #
21
+ # source "./additions"
22
+ # files "robots.txt", "not_found.html"
23
+ # build_to_and_reset "./build/"
24
+ # end
25
+ class Site
26
+ # @note Please dont use this, this is not meant to be used outside at all
27
+ Page = Struct.new(:path, :content)
28
+
29
+ def initialize
30
+ @path = nil
31
+ @routes = []
32
+ @files = []
33
+ end
34
+
35
+ # Creates a new html page on path
36
+ # @param path [String] route path on where to build
37
+ # @param page [HTML::Builder, HTML::Element, String] content that will be put inside the page
38
+ # return [void]
39
+ def route(path, page)
40
+ @routes << Page.new(path, page)
41
+ end
42
+
43
+ # Creates a new file on path
44
+ # @param path [String] route path on where to build, including the name of the file
45
+ # @param string [String] content that will be put inside the file
46
+ # return [void]
47
+ def file(path, string)
48
+ @files << Page.new(path, string)
49
+ end
50
+
51
+ # Builds the site
52
+ # @param path [String] path on where to build
53
+ # return [void]
54
+ def build_to(path)
55
+ @path = path
56
+ @routes.each do |route|
57
+ create_file(route, 'index.html')
58
+ end
59
+ @files.each do |file|
60
+ create_file(file)
61
+ end
62
+ puts '[LOG] Finished creating files'
63
+ end
64
+
65
+ alias build build_to
66
+
67
+ # Create assets easier
68
+ # @yield Start block of asset
69
+ # @example
70
+ # s = Alister::Site.new
71
+ # s.assets do
72
+ # source "./assets"
73
+ # enable_webp_conversion unless DEBUG
74
+ # file "**/*"
75
+ # build_to_and_reset "./build/assets/"
76
+ # end
77
+ # return [void]
78
+ def assets(&block)
79
+ assets = Alister::Assets.new
80
+ assets.instance_eval(&block)
81
+ end
82
+
83
+ # Resets the site builder for next build
84
+ # return [void]
85
+ def reset
86
+ @path = nil
87
+ @routes = []
88
+ @files = []
89
+ end
90
+
91
+ # Builds and then resets the site builder
92
+ # @param path [String] path on where to build
93
+ # return [void]
94
+ def build_to_and_reset(path)
95
+ build_to(path)
96
+ reset
97
+ end
98
+
99
+ alias build_and_reset build_to_and_reset
100
+
101
+ private
102
+
103
+ def create_file(route, name = nil)
104
+ path = File.join(@path, route.path)
105
+ file_path = name ? File.join(path, name) : path
106
+
107
+ FileUtils.mkdir_p(File.dirname(file_path))
108
+ FileUtils.touch(file_path)
109
+
110
+ file = File.new(file_path, 'w+')
111
+ file.write(route.content.to_s)
112
+ file.close
113
+ puts "[LOG] Creating file #{file_path}"
114
+ end
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alister
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Lain Madeline
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: fileutils
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.7'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.7'
26
+ - !ruby/object:Gem::Dependency
27
+ name: webp-ffi
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.4.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: webrick
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.9'
54
+ email:
55
+ - laimadelain@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - ".rubocop.yml"
61
+ - CHANGELOG.md
62
+ - CODE_OF_CONDUCT.md
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - lib/alister.rb
67
+ - lib/alister/version.rb
68
+ - lib/assets.rb
69
+ - lib/html/builder.rb
70
+ - lib/html/element.rb
71
+ - lib/html/generate_yard_tags.rb
72
+ - lib/html/html.rb
73
+ - lib/html/yard_tags.rb
74
+ - lib/self.rb
75
+ - lib/site.rb
76
+ homepage: https://github.com/Lain62/Alister
77
+ licenses:
78
+ - MIT
79
+ metadata:
80
+ homepage_uri: https://github.com/Lain62/Alister
81
+ source_code_uri: https://github.com/Lain62/Alister
82
+ changelog_uri: https://github.com/Lain62/Alister/blob/main/CHANGELOG.md
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 3.1.0
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.6.9
98
+ specification_version: 4
99
+ summary: A pure ruby solution to static site generation
100
+ test_files: []