endleaf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e57280cf9e74833917adf64e42296f18550963bab92d7c2ccb98e7ad735d55aa
4
+ data.tar.gz: e4ebb14b254fd6614d1cf88f396ebcff36028256035a03a0d159c251347ff8f5
5
+ SHA512:
6
+ metadata.gz: 73b9cd8dd06eed1b9c5abb277339a41b4cad7941c2d29c2196e13237848250738b35a05793a7b0d2a3f7c3d96639209b9ed85a271a06328657f5220b827a3a50
7
+ data.tar.gz: 23fa2ceffaa1f8f0c466f07d4cc0645c69d5b20c73a396696c4dc3ca321cc7b1dbe77248d081bb59dff725801f77b9eef97598adb535f81c97236804f038f11c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Wittawas W
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Endleaf
2
+ Routing and utilities for static pages creation in Rails.
3
+
4
+ ## Installation
5
+ Add this line to your Rails application's Gemfile:
6
+
7
+ ```ruby
8
+ gem "endleaf"
9
+ ```
10
+
11
+ ## Usage
12
+ - Use with Ruby on Rails only.
13
+ - Add routes to `config/routes.rb`
14
+
15
+ ```ruby
16
+ scope module: 'endleaf' do
17
+ get '/pages/:page', to: 'pages#show', as: :page
18
+ end
19
+ ```
20
+ - Create pages in `app/views/pages` with filenames corresponding to their routes.
21
+
22
+ ```ruby
23
+ # can be used in specific routes e.g. homepage
24
+ # this route is rendered from app/view/pages/home.html.erb (or any supported extensions)
25
+ root 'endleaf/pages#show' , page: 'home'
26
+
27
+ # this route is rendered from app/view/pages/about.html.erb (or any supported extensions)
28
+ get 'endleaf/pages#show' , page: 'about'
29
+ ```
30
+
31
+ - Pre-render pages into the `public` directory. Pre-rendered pages can be served by a web server and are more cache-friendly.
32
+
33
+ ```shell
34
+ bundle exec rake endleaf:render:generate_html
35
+ ```
36
+
37
+
38
+ ## License
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ module Endleaf
2
+ class PagesController < ApplicationController
3
+ before_action :set_layout
4
+
5
+ def show
6
+ render template: "pages/#{params[:page]}"
7
+ end
8
+
9
+ private
10
+
11
+ def set_layout
12
+ self.class.layout('endleaf')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Endleaf</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ </head>
7
+
8
+ <body>
9
+ <p>Override this with app/views/layouts/endleaf.html.erb</p>
10
+ <%= yield %>
11
+ </body>
12
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ scope module: 'endleaf' do
3
+ get '/pages/:page', to: 'pages#show', as: :page
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Endleaf
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Endleaf
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Endleaf
2
+ VERSION = "0.1.0"
3
+ end
data/lib/endleaf.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "endleaf/version"
2
+ require "endleaf/engine"
3
+
4
+ module Endleaf
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,38 @@
1
+ namespace :endleaf do
2
+ namespace :render do
3
+ desc 'Render and save static pages as HTML'
4
+
5
+ task :generate_html => :environment do
6
+ # Include the necessary modules to access render_to_string
7
+ controller_path = 'endleaf/pages'
8
+ action_name = 'show'
9
+
10
+ # Create a controller instance
11
+ controller = ActionController::Base.new
12
+ controller.request = ActionDispatch::Request.new({})
13
+
14
+ # Set the controller path and action name
15
+ controller.params = { controller: controller_path, action: action_name }
16
+
17
+ # Define the directory containing your static pages within the engine
18
+ pages_directory = Rails.root.join('app', 'views', 'pages')
19
+
20
+ # Loop through each file in the pages directory
21
+ Dir.glob("#{pages_directory}/*.html.erb") do |file|
22
+ # Extract the filename without the directory and extension
23
+ filename = File.basename(file, '.html.erb')
24
+
25
+ # Render the page
26
+ html_content = controller.render_to_string(template: "pages/#{filename}", layout: 'endleaf')
27
+
28
+ # Define the path to save the HTML file in the public directory
29
+ save_path = Rails.root.join('public', "#{filename}.html")
30
+
31
+ # Save the rendered HTML to the file
32
+ File.write(save_path, html_content)
33
+
34
+ puts "Rendered and saved #{filename}.html"
35
+ end
36
+ end
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: endleaf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wittawas W
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ description: Routing and utilities for static pages creation in Rails.
28
+ email:
29
+ - start@wittawasw.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/controllers/endleaf/pages_controller.rb
38
+ - app/views/layouts/endleaf.html.erb
39
+ - config/routes.rb
40
+ - lib/endleaf.rb
41
+ - lib/endleaf/engine.rb
42
+ - lib/endleaf/railtie.rb
43
+ - lib/endleaf/version.rb
44
+ - lib/tasks/endleaf/render.rake
45
+ homepage: https://github.com/wittawasw/endleaf
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://github.com/wittawasw/endleaf
50
+ source_code_uri: https://github.com/wittawasw/endleaf
51
+ changelog_uri: https://github.com/wittawasw/endleaf
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.4.19
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Routing and utilities for static pages creation in Rails.
71
+ test_files: []