endleaf 0.1.1 → 0.2.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 +4 -4
- data/README.md +7 -1
- data/app/controllers/endleaf/pages_controller.rb +4 -1
- data/lib/endleaf/version.rb +1 -1
- data/lib/tasks/endleaf/render.rake +32 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dce8df1c349a41f7306c53756797ceb9ca48596ea457f09b1dd3af5be062808
|
4
|
+
data.tar.gz: 0eedffd912530827f20871c74510b1ffa755bb87406d278be90e2d6cfecd7aa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9811eaf75bab78144af3a6aff8c46990bd6295bc923c8ebb5d37eb1b27cfd1e5a4e7f277f652abacba70a499de98c089c14fb638afe8f9a5c5f30fb25a90828
|
7
|
+
data.tar.gz: 9876dce6918c40c5dfc72da5f5c147e91183ec73619fa0075425522067d755e186952ab6837de368f5fdcc79bd31d5f216e45c0e1235ffaba31f9772ec856296
|
data/README.md
CHANGED
@@ -10,14 +10,20 @@ gem "endleaf"
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
- Use with Ruby on Rails only.
|
13
|
+
- Create pages in `app/views/pages` with filenames corresponding to their routes.
|
13
14
|
- Add routes to `config/routes.rb`
|
14
15
|
|
15
16
|
```ruby
|
17
|
+
# Simple usage
|
16
18
|
scope module: 'endleaf' do
|
17
19
|
get '/pages/:page', to: 'pages#show', as: :page
|
18
20
|
end
|
21
|
+
|
22
|
+
# Use scope and constraints to achieve routes into sub directories
|
23
|
+
scope "/pages", constraints: { path: /pages\/.*/ } do
|
24
|
+
get "*page", to: "endleaf/pages#show"
|
25
|
+
end
|
19
26
|
```
|
20
|
-
- Create pages in `app/views/pages` with filenames corresponding to their routes.
|
21
27
|
|
22
28
|
```ruby
|
23
29
|
# can be used in specific routes e.g. homepage
|
data/lib/endleaf/version.rb
CHANGED
@@ -3,35 +3,56 @@ namespace :endleaf do
|
|
3
3
|
desc 'Render and save static pages as HTML'
|
4
4
|
|
5
5
|
task :generate_html => :environment do
|
6
|
-
#
|
6
|
+
# Manually set the controller path and action name
|
7
7
|
controller_path = 'endleaf/pages'
|
8
8
|
action_name = 'show'
|
9
9
|
|
10
|
-
# Create a controller instance
|
11
10
|
controller = ActionController::Base.new
|
12
11
|
controller.request = ActionDispatch::Request.new({})
|
13
12
|
|
14
13
|
# Set the controller path and action name
|
15
14
|
controller.params = { controller: controller_path, action: action_name }
|
16
15
|
|
16
|
+
# Set static pages directory
|
17
|
+
pages_dir = "pages"
|
18
|
+
|
17
19
|
# Define the directory containing your static pages within the engine
|
18
|
-
pages_directory = Rails.root.join(
|
20
|
+
pages_directory = Rails.root.join("app", "views", pages_dir)
|
21
|
+
|
22
|
+
# Supported template extensions
|
23
|
+
template_extensions = %w[html.erb erb html.haml haml html.slim slim]
|
24
|
+
|
25
|
+
puts "#{pages_directory}/**/*.{#{template_extensions.join(',')}}"
|
19
26
|
|
20
|
-
# Loop through each file in the pages directory
|
21
|
-
Dir.glob("#{pages_directory}
|
22
|
-
# Extract the
|
23
|
-
|
27
|
+
# Loop through each file in the pages directory and subdirectories
|
28
|
+
Dir.glob("#{pages_directory}/**/*.{#{template_extensions.join(',')}}") do |file|
|
29
|
+
# Extract the relative path from the pages directory
|
30
|
+
relative_path = Pathname.new(file).relative_path_from(pages_directory).to_s
|
24
31
|
|
25
|
-
#
|
26
|
-
|
32
|
+
# Extract the filename without the extension
|
33
|
+
filename = File.basename(file, '.*')
|
34
|
+
|
35
|
+
# Construct the absolute path to the template file
|
36
|
+
template_path = "#{pages_dir}/#{relative_path.sub(/\.(#{template_extensions.join('|')})$/, '')}"
|
37
|
+
puts "template: #{template_path}"
|
38
|
+
|
39
|
+
# Render the page using the controller's render_to_string method
|
40
|
+
html_content = controller.render_to_string(
|
41
|
+
template: template_path,
|
42
|
+
layout: "endleaf"
|
43
|
+
)
|
27
44
|
|
28
45
|
# Define the path to save the HTML file in the public directory
|
29
|
-
save_path
|
46
|
+
# Modify save_path logic to generate 'example/index.html' format
|
47
|
+
save_path = Rails.root.join('public', "#{relative_path.sub(/\.html\.erb$/, '')}/index.html")
|
48
|
+
|
49
|
+
# Create directories if they don't exist
|
50
|
+
FileUtils.mkdir_p(File.dirname(save_path))
|
30
51
|
|
31
52
|
# Save the rendered HTML to the file
|
32
53
|
File.write(save_path, html_content)
|
33
54
|
|
34
|
-
puts "Rendered and saved #{
|
55
|
+
puts "Rendered and saved #{save_path}"
|
35
56
|
end
|
36
57
|
end
|
37
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: endleaf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wittawas W
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -47,7 +47,7 @@ licenses:
|
|
47
47
|
metadata:
|
48
48
|
homepage_uri: https://github.com/wittawasw/endleaf
|
49
49
|
source_code_uri: https://github.com/wittawasw/endleaf
|
50
|
-
changelog_uri: https://github.com/wittawasw/endleaf
|
50
|
+
changelog_uri: https://github.com/wittawasw/endleaf/blob/main/changelog.md
|
51
51
|
post_install_message:
|
52
52
|
rdoc_options: []
|
53
53
|
require_paths:
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.4.
|
66
|
+
rubygems_version: 3.4.20
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Routing and utilities for static pages creation in Rails.
|