endleaf 0.2.0 → 0.3.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
2
  SHA256:
3
- metadata.gz: 1dce8df1c349a41f7306c53756797ceb9ca48596ea457f09b1dd3af5be062808
4
- data.tar.gz: 0eedffd912530827f20871c74510b1ffa755bb87406d278be90e2d6cfecd7aa9
3
+ metadata.gz: 90f0e34500f5b54264548be3dcc719321a373698836ab9e4947895f76525ec7e
4
+ data.tar.gz: 786a0759dc2c2dc0d685bfb94e9adc560476a86aeb25240b9d5add113b64a3f6
5
5
  SHA512:
6
- metadata.gz: d9811eaf75bab78144af3a6aff8c46990bd6295bc923c8ebb5d37eb1b27cfd1e5a4e7f277f652abacba70a499de98c089c14fb638afe8f9a5c5f30fb25a90828
7
- data.tar.gz: 9876dce6918c40c5dfc72da5f5c147e91183ec73619fa0075425522067d755e186952ab6837de368f5fdcc79bd31d5f216e45c0e1235ffaba31f9772ec856296
6
+ metadata.gz: 4304bce0e6ccd3d3e56f272b948d2dbf8ef7de06c016f25452ee9994ad494450222be0214dae79e9000bec431737dc7a08af753e60a9f3d52dfc785a2c8f87fd
7
+ data.tar.gz: 3353e33205c82259354930e068d08d6c54e7f9e3baee42860151e2980393b19ec4497e35c6d0a185be323362fab01ea29522337befa0834d6c1b54ed1f6945bd
data/README.md CHANGED
@@ -23,6 +23,13 @@ end
23
23
  scope "/pages", constraints: { path: /pages\/.*/ } do
24
24
  get "*page", to: "endleaf/pages#show"
25
25
  end
26
+
27
+ # With custom path and layout
28
+ # path: app/views/posts
29
+ # layout: app/views/layouts/posts.html.erb
30
+ scope "/posts", constraints: { path: /posts\/.*/ } do
31
+ get "*page", to: "endleaf/pages#show", as: :endleaf_posts_post, defaults: { path: "posts", layout: "posts" }
32
+ end
26
33
  ```
27
34
 
28
35
  ```ruby
@@ -38,6 +45,14 @@ get 'endleaf/pages#show' , page: 'about'
38
45
 
39
46
  ```shell
40
47
  bundle exec rake endleaf:render:generate_html
48
+
49
+ # custom path, layout, output with variables [path,layout,output]
50
+ # Example:
51
+ # path: app/views/posts
52
+ # layout: app/views/layouts/posts.html.erb
53
+ # output: public/static/posts
54
+ bundle exec rake endleaf:render:generate_html\[posts,posts,static\/posts\]
55
+
41
56
  ```
42
57
 
43
58
 
@@ -6,13 +6,29 @@ module Endleaf
6
6
  path_segments = params[:page].split('/')
7
7
  view_path = path_segments.join('/')
8
8
 
9
- render template: "pages/#{view_path}"
9
+ render template: "#{path}/#{view_path}"
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def set_layout
15
- self.class.layout('endleaf')
15
+ self.class.layout(page_layout)
16
+ end
17
+
18
+ def page_layout
19
+ unless params[:layout].blank?
20
+ params[:layout]
21
+ else
22
+ Endleaf::Config::DEFAULT_LAYOUT
23
+ end
24
+ end
25
+
26
+ def path
27
+ unless params[:path].blank?
28
+ params[:path]
29
+ else
30
+ Endleaf::Config::DEFAULT_PATH
31
+ end
16
32
  end
17
33
  end
18
34
  end
@@ -0,0 +1,6 @@
1
+ module Endleaf
2
+ module Config
3
+ DEFAULT_LAYOUT = "endleaf".freeze # Default layout
4
+ DEFAULT_PATH = "pages".freeze # Default path
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Endleaf
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0".freeze
3
3
  end
data/lib/endleaf.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "endleaf/version"
2
2
  require "endleaf/engine"
3
+ require "endleaf/config"
3
4
 
4
5
  module Endleaf
5
6
  # Your code goes here...
@@ -1,11 +1,16 @@
1
1
  namespace :endleaf do
2
2
  namespace :render do
3
- desc 'Render and save static pages as HTML'
3
+ desc "Render and save static pages as HTML"
4
4
 
5
- task :generate_html => :environment do
5
+ task :generate_html, [:path, :layout, :output] => :environment do |t, args|
6
6
  # Manually set the controller path and action name
7
- controller_path = 'endleaf/pages'
8
- action_name = 'show'
7
+ controller_path = "endleaf/pages"
8
+ action_name = "show"
9
+
10
+ # Set static pages directory and layout
11
+ page_path = args[:path] || Endleaf::Config::DEFAULT_PATH
12
+ layout = args[:layout] || Endleaf::Config::DEFAULT_LAYOUT
13
+ output = args[:output].to_s
9
14
 
10
15
  controller = ActionController::Base.new
11
16
  controller.request = ActionDispatch::Request.new({})
@@ -13,11 +18,8 @@ namespace :endleaf do
13
18
  # Set the controller path and action name
14
19
  controller.params = { controller: controller_path, action: action_name }
15
20
 
16
- # Set static pages directory
17
- pages_dir = "pages"
18
-
19
21
  # Define the directory containing your static pages within the engine
20
- pages_directory = Rails.root.join("app", "views", pages_dir)
22
+ pages_directory = Rails.root.join("app", "views", page_path)
21
23
 
22
24
  # Supported template extensions
23
25
  template_extensions = %w[html.erb erb html.haml haml html.slim slim]
@@ -33,18 +35,18 @@ namespace :endleaf do
33
35
  filename = File.basename(file, '.*')
34
36
 
35
37
  # Construct the absolute path to the template file
36
- template_path = "#{pages_dir}/#{relative_path.sub(/\.(#{template_extensions.join('|')})$/, '')}"
38
+ template_path = "#{page_path}/#{relative_path.sub(/\.(#{template_extensions.join('|')})$/, '')}"
37
39
  puts "template: #{template_path}"
38
40
 
39
41
  # Render the page using the controller's render_to_string method
40
42
  html_content = controller.render_to_string(
41
43
  template: template_path,
42
- layout: "endleaf"
44
+ layout: layout
43
45
  )
44
46
 
45
47
  # Define the path to save the HTML file in the public directory
46
48
  # Modify save_path logic to generate 'example/index.html' format
47
- save_path = Rails.root.join('public', "#{relative_path.sub(/\.html\.erb$/, '')}/index.html")
49
+ save_path = Rails.root.join('public', output, "#{relative_path.sub(/\.html\.erb$/, '')}/index.html")
48
50
 
49
51
  # Create directories if they don't exist
50
52
  FileUtils.mkdir_p(File.dirname(save_path))
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.2.0
4
+ version: 0.3.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-10-01 00:00:00.000000000 Z
11
+ date: 2023-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,6 +37,7 @@ files:
37
37
  - app/controllers/endleaf/pages_controller.rb
38
38
  - app/views/layouts/endleaf.html.erb
39
39
  - lib/endleaf.rb
40
+ - lib/endleaf/config.rb
40
41
  - lib/endleaf/engine.rb
41
42
  - lib/endleaf/railtie.rb
42
43
  - lib/endleaf/version.rb