inert 0.2.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f79a5379e8bc3c2efef1112aa3594a0d21c5ebd2
4
- data.tar.gz: dac79be86b3228b75c50344d97a1af2131efa962
2
+ SHA256:
3
+ metadata.gz: 249dee2f97dfd03ef27c640fe86bbeb93df44d281b2de5d8ded5c42922b21761
4
+ data.tar.gz: d9459ba71fc85a5021c275267c8d12823783c0112573a1cc628051d1ea002311
5
5
  SHA512:
6
- metadata.gz: 958d318d85847d81d45b76d7e2a42f2e6b8d437b0dc1fa896676ddd0e4ae4603fa9aac2bdf575fd53cc02f2751276d5374bb3aebfdbaae83165c9c79ef4a3194
7
- data.tar.gz: 96b3d288ead98c0e282eddec337bcd01de90d32a8c1eff0ad11b86ea09d5860c6dd28fe01b4eb621e47b6c2b6cd24ffe0e472248a254e82102d0b5761bcf5552
6
+ metadata.gz: e439eddbee4a90c722670cdce5861b99cd873a8c10c5545c9c67eb84c26d37c03bc44d1511cdb2bf6a54455e66783d7be0cfc1bef50be15fe4f340ebfe83c8e7
7
+ data.tar.gz: 3f45d74a98b1d3ed566a4c116d083f5b76b0a9d92048d84520c1eaddef75b4f93a22ba858aa25fc83779863756caced4dcc8cfd64bb040bf10f89380fd76d760
data/README.md CHANGED
@@ -46,11 +46,11 @@ Inert.config do |inert|
46
46
  "Inert v#{Inert::VERSION}"
47
47
  end
48
48
  end
49
-
49
+
50
50
  inert.app do
51
51
  plugin :h
52
52
  end
53
-
53
+
54
54
  inert.routes do |r|
55
55
  r.on "employees.html" do
56
56
  @employees = [] # Read in actual data here
@@ -84,6 +84,36 @@ in `static/` wherever you'd just use the filename itself:
84
84
  <img src="<%= timestamp_path "some_image_in_static_folder.png" %>">
85
85
  ```
86
86
 
87
+ ## Asset Minification
88
+
89
+ Use asset minification to compile and compress all your CSS and JS assets into
90
+ a single file.
91
+
92
+ ```ruby
93
+ # Inertfile
94
+
95
+ Inert.config do |inert|
96
+ inert.app do
97
+ plugin :assets, css: %w"text.css layout.css"
98
+ compile_assets if Inert.building?
99
+ end
100
+
101
+ inert.routes do |r|
102
+ r.assets
103
+ end
104
+ end
105
+ ```
106
+
107
+ And inside your layout, use the `assets` helper with the name of the asset group:
108
+
109
+ ```ruby
110
+ <%= assets(:css) %>
111
+ ```
112
+
113
+ Make sure you put your assets in `assets/group`. For the example above, you'd have
114
+ `assets/css/text.css` and `assets/css/layout.css`.
115
+
116
+
87
117
  ## Live Reloads
88
118
 
89
119
  Use the `roda-live_reload` gem to enable live reloads:
@@ -98,11 +128,11 @@ gem "puma" # Webrick wont' currently work with roda-live_reload
98
128
  # Inertfile
99
129
  Inert.config do |inert|
100
130
  inert.app do
101
- plugin :live_reload if ENV["RACK_ENV"] == "development"
131
+ plugin :live_reload if Inert.development?
102
132
  end
103
133
 
104
134
  inert.routes do |r|
105
- r.live_reload if ENV["RACK_ENV"] == "development"
135
+ r.live_reload if Inert.development?
106
136
  end
107
137
  end
108
138
  ```
data/exe/inert CHANGED
@@ -2,17 +2,7 @@
2
2
  require "inert/config"
3
3
 
4
4
  inertfile = File.join(Dir.pwd, "Inertfile")
5
- if File.exist?(inertfile)
6
- load inertfile
7
- end
5
+ Inert::Config.load(inertfile)
8
6
 
9
- case ARGV[0]
10
- when "build"
11
- ENV["RACK_ENV"] = "production"
12
- require "inert"
13
- Inert.build
14
- else
15
- ENV["RACK_ENV"] = "development"
16
- require "inert"
17
- Inert.start
18
- end
7
+ require "inert"
8
+ Inert::CLI.start
@@ -2,31 +2,37 @@
2
2
  require "roda"
3
3
 
4
4
  module Inert
5
- class Middleware < Roda
5
+ class App < Roda
6
6
  plugin :render,
7
- cache: ENV["RACK_ENV"] == "production",
7
+ cache: Inert.building?,
8
8
  views: Inert.config.views
9
9
 
10
10
  plugin :partials
11
11
  plugin :public, root: "static"
12
12
  plugin :content_for
13
13
 
14
- class_exec &Inert.config.app
14
+ if Inert.development?
15
+ plugin :common_logger
16
+ plugin :exception_page
17
+ plugin :error_handler do |e|
18
+ next exception_page(e)
19
+ end
20
+ end
15
21
 
16
- attr_reader :page
22
+ class_exec(&Inert.config.app)
17
23
 
18
24
  route do |r|
19
25
  r.public
20
26
 
21
- Inert.config.routes.call(r)
27
+ instance_exec(r, &Inert.config.routes)
22
28
 
23
29
  view_file = r.remaining_path.dup
24
- view_file << "index.html" if view_file.end_with?("/")
30
+ view_file << "index" if view_file.end_with?("/")
25
31
 
26
32
  begin
27
33
  page = Page.load_from_file(File.join(Inert.view_path, view_file))
28
34
  rescue Errno::ENOENT
29
- r.halt([404, {}, ["Not found"]])
35
+ r.halt([404, {}, ["#{view_file} Not found"]])
30
36
  end
31
37
 
32
38
  @page = page.frontmatter
@@ -34,11 +40,15 @@ module Inert
34
40
  view(inline: page.body, layout: page.layout, template_class: Tilt[page.filename])
35
41
  end
36
42
 
37
- class_exec &Inert.config.helpers
43
+ class_exec(&Inert.config.helpers)
38
44
 
39
45
  def inline(file)
40
46
  File.read(File.join(Inert.view_path, file))
41
47
  end
48
+
49
+ def page
50
+ @page ||= OpenStruct.new
51
+ end
42
52
  end
43
53
  end
44
54
 
data/lib/inert/builder.rb CHANGED
@@ -1,26 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
  require "fileutils"
3
- require "set"
4
3
  require "oga"
5
4
  require "uri"
5
+ require "rack"
6
+ require_relative "history"
7
+ require_relative "logger"
6
8
 
7
9
  module Inert
8
10
  class Builder
9
- attr_accessor :app, :build_path
11
+ attr_accessor :app, :build_destination
10
12
  attr_reader :queue, :history
11
13
 
12
- def initialize(app)
14
+ attr_accessor :logger
15
+
16
+ def initialize(app, build_destination: "./build")
13
17
  @app = app
14
18
  @queue = []
15
- @history = Set.new
16
- @build_path = "./build"
19
+ @history = History.new
20
+ @build_destination = build_destination
21
+
22
+ Logger.configure(self)
17
23
  end
18
24
 
19
25
  def call(starting_url)
26
+ copy_static
27
+
20
28
  save(starting_url)
29
+ history.add(starting_url)
21
30
 
22
31
  while (url = queue.pop)
23
- next if history.include?(url) || url == "#"
32
+ next if history.include?(url) || is_anchor?(url) || is_remote?(url)
24
33
 
25
34
  save(url)
26
35
  history.add(url)
@@ -28,13 +37,13 @@ module Inert
28
37
  end
29
38
 
30
39
  def save(url)
31
- warn "Saving #{url}"
40
+ logger.info { "Saving #{url}" }
32
41
  request = Rack::MockRequest.new(app)
33
42
 
34
43
  dest = URI(url.dup).path
35
44
  dest << "index.html" if dest.end_with?("/")
36
45
  dest << ".html" unless dest =~ /\.\w+$/
37
- dest = File.expand_path(dest[1..-1], build_path)
46
+ dest = File.expand_path(dest[1..-1], build_destination)
38
47
 
39
48
  FileUtils.mkdir_p(File.dirname(dest))
40
49
 
@@ -59,5 +68,17 @@ module Inert
59
68
  end
60
69
  end
61
70
  end
71
+
72
+ def copy_static
73
+ FileUtils.cp_r(app.opts[:public_root]+"/.", build_destination)
74
+ end
75
+
76
+ def is_anchor?(url)
77
+ url.start_with?("#")
78
+ end
79
+
80
+ def is_remote?(url)
81
+ url =~ /\A(\w+):/ || url.start_with?("//")
82
+ end
62
83
  end
63
84
  end
data/lib/inert/cli.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "thor"
4
+
5
+ module Inert
6
+ class CLI < Thor
7
+ default_command :server
8
+
9
+ desc "build", "Build site"
10
+ def build
11
+ Inert.build
12
+ end
13
+
14
+ desc "server", "Run server"
15
+ method_option :port, aliases: "-p", desc: "port to listen on", type: :numeric, default: 3000
16
+ method_option :bind, aliases: "-b", desc: "address to listen on", type: :string, default: "localhost"
17
+ method_option :server, aliases: "-s", desc: "server to use", type: :string
18
+ def server
19
+ Inert.start(server: options.server, host: options.bind, port: options.port)
20
+ end
21
+ end
22
+ end
data/lib/inert/config.rb CHANGED
@@ -56,10 +56,15 @@ module Inert
56
56
  return @routes unless block_given?
57
57
  @routes = block
58
58
  end
59
+
60
+ def self.load(filename)
61
+ if File.exist?(filename)
62
+ Kernel.load filename
63
+ end
64
+ end
59
65
  end
60
66
 
61
- module_function
62
- def config
67
+ def self.config
63
68
  @config ||= Config.new
64
69
  yield @config if block_given?
65
70
  @config
@@ -0,0 +1,18 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "set"
4
+ require "forwardable"
5
+
6
+ module Inert
7
+ class History
8
+ extend Forwardable
9
+
10
+ def initialize
11
+ @entries = Set.new
12
+ end
13
+
14
+ def_delegator :@entries, :add
15
+ def_delegator :@entries, :include?
16
+ def_delegator :@entries, :length
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "logger"
4
+
5
+ module Inert
6
+ class Logger < ::Logger
7
+ def self.configure(receiver, attr_meth = :logger)
8
+ instance = new($stdout)
9
+ receiver.public_send("#{attr_meth}=", instance)
10
+ instance
11
+ end
12
+ end
13
+ end
data/lib/inert/page.rb CHANGED
@@ -21,6 +21,15 @@ module Inert
21
21
  raise Errno::ENOENT if filename.nil?
22
22
 
23
23
  body = File.read(filename)
24
+ body, frontmatter = extract_frontmatter(body)
25
+ new(body: body, frontmatter: frontmatter, filename: filename)
26
+ end
27
+
28
+ def self.find_file(filename)
29
+ Dir[filename + ".*"].first
30
+ end
31
+
32
+ def self.extract_frontmatter(body)
24
33
  frontmatter = {}
25
34
 
26
35
  body = body.gsub(/---(.*)---/m) do |m|
@@ -28,11 +37,7 @@ module Inert
28
37
  ""
29
38
  end.lstrip
30
39
 
31
- new(body: body, frontmatter: frontmatter, filename: filename)
32
- end
33
-
34
- def self.find_file(filename)
35
- Dir[filename + ".*"].first
40
+ [body, frontmatter]
36
41
  end
37
42
  end
38
43
  end
@@ -0,0 +1,3 @@
1
+ module Inert
2
+ VERSION = "0.4.0".freeze
3
+ end
data/lib/inert.rb CHANGED
@@ -1,31 +1,45 @@
1
1
  # frozen_string_literal: true
2
+ require_relative "inert/version"
2
3
  require_relative "inert/config"
4
+ require_relative "inert/cli"
3
5
 
4
6
  module Inert
5
7
  module_function
6
8
 
7
- def start
8
- app = Rack::Builder.app do
9
- if ENV["RACK_ENV"] != "production"
10
- use Rack::ShowExceptions
11
- use Rack::CommonLogger
12
- end
9
+ def start(server: nil, host: nil, port: nil)
10
+ ENV["RACK_ENV"] = "development"
11
+ require_relative "inert/app"
13
12
 
14
- run Inert::Middleware
15
- end
13
+ require "rackup/server"
16
14
 
17
- Rack::Server.start(app: app)
15
+ Rackup::Server.start({
16
+ app: Inert::App,
17
+ server: server,
18
+ Host: host,
19
+ Port: port,
20
+ AccessLog: []
21
+ })
18
22
  end
19
23
 
20
24
  def build
21
- Inert::Builder.new(Inert::Middleware).call("/")
25
+ ENV["RACK_ENV"] = "production"
26
+ require_relative "inert/app"
27
+
28
+ Inert::Builder.new(Inert::App).call("/")
22
29
  end
23
30
 
24
31
  def view_path
25
32
  File.expand_path(Inert.config.views, Dir.pwd)
26
33
  end
34
+
35
+ def development?
36
+ ENV["RACK_ENV"] == "development"
37
+ end
38
+
39
+ def building?
40
+ !development?
41
+ end
27
42
  end
28
43
 
29
44
  require_relative "inert/page"
30
45
  require_relative "inert/builder"
31
- require_relative "inert/middleware"
metadata CHANGED
@@ -1,22 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Daniels
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2017-11-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ostruct
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.5'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0.5'
26
+ - !ruby/object:Gem::Dependency
27
+ name: logger
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rack
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: rackup
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "<"
72
+ - !ruby/object:Gem::Version
73
+ version: '3.0'
13
74
  - !ruby/object:Gem::Dependency
14
75
  name: roda
15
76
  requirement: !ruby/object:Gem::Requirement
16
77
  requirements:
17
78
  - - ">="
18
79
  - !ruby/object:Gem::Version
19
- version: '2.0'
80
+ version: '3.13'
20
81
  - - "<"
21
82
  - !ruby/object:Gem::Version
22
83
  version: '4.0'
@@ -26,7 +87,7 @@ dependencies:
26
87
  requirements:
27
88
  - - ">="
28
89
  - !ruby/object:Gem::Version
29
- version: '2.0'
90
+ version: '3.13'
30
91
  - - "<"
31
92
  - !ruby/object:Gem::Version
32
93
  version: '4.0'
@@ -50,6 +111,26 @@ dependencies:
50
111
  - - "<"
51
112
  - !ruby/object:Gem::Version
52
113
  version: '4.0'
114
+ - !ruby/object:Gem::Dependency
115
+ name: thor
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '1.0'
121
+ - - "<"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '1.0'
131
+ - - "<"
132
+ - !ruby/object:Gem::Version
133
+ version: '3.0'
53
134
  - !ruby/object:Gem::Dependency
54
135
  name: oga
55
136
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +151,26 @@ dependencies:
70
151
  - - "<"
71
152
  - !ruby/object:Gem::Version
72
153
  version: '4.0'
73
- description:
154
+ - !ruby/object:Gem::Dependency
155
+ name: webrick
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '1.8'
161
+ - - "<"
162
+ - !ruby/object:Gem::Version
163
+ version: '2.0'
164
+ type: :runtime
165
+ prerelease: false
166
+ version_requirements: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '1.8'
171
+ - - "<"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.0'
74
174
  email: adam@mediadrive.ca
75
175
  executables:
76
176
  - inert
@@ -80,15 +180,18 @@ files:
80
180
  - README.md
81
181
  - exe/inert
82
182
  - lib/inert.rb
183
+ - lib/inert/app.rb
83
184
  - lib/inert/builder.rb
185
+ - lib/inert/cli.rb
84
186
  - lib/inert/config.rb
85
- - lib/inert/middleware.rb
187
+ - lib/inert/history.rb
188
+ - lib/inert/logger.rb
86
189
  - lib/inert/page.rb
190
+ - lib/inert/version.rb
87
191
  homepage: https://github.com/adam12/inert
88
192
  licenses:
89
193
  - MIT
90
194
  metadata: {}
91
- post_install_message:
92
195
  rdoc_options: []
93
196
  require_paths:
94
197
  - lib
@@ -103,9 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
206
  - !ruby/object:Gem::Version
104
207
  version: '0'
105
208
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.5.2
108
- signing_key:
209
+ rubygems_version: 4.0.3
109
210
  specification_version: 4
110
211
  summary: An experimental static site builder with unambitious goals
111
212
  test_files: []