simpleblog 0.0.1 → 1.0.1

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: 9f5eae049cc2930e851eaaf6d32a7230932f8b1044276554e856fa21cc3a1875
4
- data.tar.gz: 0a690b86338a7dd6d2f6697c619c5db835bcd4a36108ab51920be5b34d5d2a3a
3
+ metadata.gz: ab03e15d27ae35ba6d80a517e49038cc3a1371b517149731914788a89961baab
4
+ data.tar.gz: c970ef75bae07476a32c94e978c40751e839a26ea980f00a55e97f3533b9aa09
5
5
  SHA512:
6
- metadata.gz: c9ea4abd1efd2938941daed5efa33bf8e1d01c388e2491b8e5e426fa68d9f05a219f9e53790371a17e4af32aa1508c8c92f1835edf07734ee2be8d2dd1c4603d
7
- data.tar.gz: 4bd09d0b6b58d518c8b75372a8e5b9bbd9bc9d467ce69aebc8b288c780b3d011ea83a40645e47cdbbda3e2aba5f7c6b283905a3ba2ce51399ce4149107ba8492
6
+ metadata.gz: e19787714a42d112d61c60415f6a8848730c0c67a8997262ea3b138a84c22591448fc23042d0f667775617584b52042f5f5355deb854fbdb8d8693df25ee989f
7
+ data.tar.gz: d2e504c5375b5d27a19b7d84ad82ad6d4cd1d198aa337011be2a81629ea31c39cb242d638623975cc18dd7d49d9054b627c7934a81570d8d864e46b9846d9b90
@@ -0,0 +1,30 @@
1
+ class Post
2
+ def self.build_list_of_posts(posts)
3
+ posts.map do |id, post_content|
4
+ Post.new(id, post_content)
5
+ end
6
+ end
7
+
8
+ attr_reader :id, :post_content
9
+
10
+ def initialize(id, post_content)
11
+ @id = id
12
+ @post_content = post_content
13
+ end
14
+
15
+ def tags
16
+ post_content["tags"].gsub(/\s+/, "").split(",")
17
+ end
18
+
19
+ private
20
+
21
+ def method_missing(method, *args, &block)
22
+ if post_content[method.to_s]
23
+ self.class.define_method(method.to_s) do
24
+ post_content[method.to_s]
25
+ end
26
+
27
+ send method, *args, &block
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ require "pathname"
2
+
3
+ module Standard
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :simpleblog
6
+
7
+ rake_tasks do
8
+ load Pathname.new(__dir__).join("rake.rb")
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ desc "Install simpleblog basic structure"
2
+ task :"simpleblog:install" do
3
+ Dir.mkdir("app/posts") unless Dir.exist?("app/posts")
4
+
5
+ copy_template_file("app/posts/posts.yml")
6
+ copy_template_file("app/posts/1.md")
7
+ copy_template_file("app/posts/2.md")
8
+
9
+ copy_template_file("app/controllers/blog_controller.rb")
10
+ copy_template_file("app/controllers/home_controller.rb")
11
+
12
+ Dir.mkdir("app/views/blog") unless Dir.exist?("app/views/blog")
13
+ Dir.mkdir("app/views/home") unless Dir.exist?("app/views/home")
14
+
15
+ copy_template_file("app/views/blog/index.html.erb")
16
+ copy_template_file("app/views/blog/show.html.erb")
17
+ copy_template_file("app/views/home/index.html.erb")
18
+ copy_template_file("app/views/layouts/application.html.erb")
19
+
20
+ Dir.mkdir("app/assets/stylesheets/layouts") unless Dir.exist?("app/assets/stylesheets/layouts")
21
+
22
+ copy_template_file("app/assets/stylesheets/blog.scss")
23
+ copy_template_file("app/assets/stylesheets/rouge.scss.erb")
24
+ copy_template_file("app/assets/stylesheets/layouts/application.scss")
25
+
26
+ copy_template_file("app/helpers/blog_helper.rb")
27
+
28
+ copy_template_file("config/routes.rb")
29
+ end
30
+
31
+ def copy_template_file(path)
32
+ gem_path = File.dirname(__dir__)
33
+
34
+ if File.exist?(path)
35
+ $stdout.puts "#{path} already exist. Do you want to override? (y/n) default: y"
36
+ input = $stdin.gets.chomp
37
+
38
+ return if input == "n"
39
+
40
+ p "Overriden: #{path}"
41
+ else
42
+ p "Created: #{path}"
43
+ end
44
+
45
+ copy_file("#{gem_path}/simpleblog/template/#{path}", path)
46
+ end
@@ -0,0 +1,3 @@
1
+ p {
2
+ color: #2E2F30;
3
+ }
@@ -0,0 +1,61 @@
1
+ .header {
2
+ background-color: #2C3E50;
3
+ text-align: center;
4
+ padding: 20px;
5
+ }
6
+
7
+ .header-inner {
8
+ width: 760px;
9
+ margin: auto;
10
+ display: flex;
11
+ justify-content: space-between;
12
+ }
13
+
14
+ .title {
15
+ text-decoration: none;
16
+ color: #fff;
17
+ text-transform: uppercase;
18
+ font-weight: 500;
19
+ font-size: 18px;
20
+ }
21
+
22
+ .link {
23
+ text-decoration: none;
24
+ color: #fff;
25
+ margin-left: 20px;
26
+ font-size: 16px;
27
+ }
28
+
29
+ .content {
30
+ max-width: 760px;
31
+ margin: 0 auto;
32
+ }
33
+
34
+ body {
35
+ font-family: Ubuntu, sans-serif;
36
+ color: #2c3e50;
37
+ margin: 0;
38
+
39
+ h1 {
40
+ color: #e74c3c;
41
+ text-shadow: 1px 1px 1px rgb(150, 150, 150);
42
+ font-weight: 500;
43
+ line-height: 1.1;
44
+ }
45
+
46
+ a {
47
+ color: #428bca;
48
+ text-decoration: none;
49
+ margin-right: 4px;
50
+ }
51
+ }
52
+
53
+ @media (max-width: 759px) {
54
+ .header-inner {
55
+ width: 100%;
56
+ }
57
+
58
+ .content {
59
+ padding: 0 10px;
60
+ }
61
+ }
@@ -0,0 +1,13 @@
1
+ <%= Rouge::Themes::Github.render %>
2
+
3
+ div.highlight {
4
+ border-radius: 5px;
5
+ padding: 5px 10px;
6
+ }
7
+
8
+ img.markdown-image {
9
+ margin: 0 auto;
10
+ display: block;
11
+ width: 100%;
12
+ height: auto;
13
+ }
@@ -0,0 +1,13 @@
1
+ class BlogController < ApplicationController
2
+ include SimpleBlogHelper
3
+
4
+ before_action :set_site_prefix
5
+
6
+ def index
7
+ @posts = SimpleBlog.list_posts(params[:tag], params[:in_progress])
8
+ end
9
+
10
+ def show
11
+ @post_content_html = SimpleBlog.render_post(params[:id])
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ class HomeController < ApplicationController
2
+ before_action :set_site_prefix
3
+
4
+ def index
5
+ end
6
+
7
+ private
8
+
9
+ def set_site_prefix
10
+ @title_prefix = "About | "
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module BlogHelper
2
+ def stringfy_date(date)
3
+ date.to_date.strftime("%b %d, %Y")
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ # My first post using SimpleBlog
2
+
3
+ **Text**
4
+
5
+ More text
6
+
7
+ ```bash
8
+ def some_code
9
+ # TODO: hello
10
+ end
11
+ ```
@@ -0,0 +1,3 @@
1
+ # Not published post
2
+
3
+ Blah
@@ -0,0 +1,12 @@
1
+ posts:
2
+ 1:
3
+ title: My first post using SimpleBlog
4
+ date: 2022-04-21
5
+ description: Description of my post
6
+ tags: sample, programming, tips, template
7
+ 2:
8
+ title: Not published post
9
+ date: 2022-04-21
10
+ description: Description of my post
11
+ tags: sample, programming, tips, template
12
+ in_progress: true
@@ -0,0 +1,10 @@
1
+ <% @posts.each do |post| %>
2
+ <a style="text-decoration: none" href=<%= blog_post_path("#{post.id}-#{post.title.parameterize}") %>>
3
+ <h1><%= post.title %></h1>
4
+ <p><%= post.description %></p>
5
+ <p><%= stringfy_date(post.date) %></p>
6
+ </a>
7
+ <% post.tags.each do |tag| %>
8
+ <a class="tag" href=<%= "#{blog_path}?tag=#{tag}" %>><%= tag %></a>
9
+ <% end %>
10
+ <% end %>
@@ -0,0 +1 @@
1
+ <%== @post_content_html %>
@@ -0,0 +1,14 @@
1
+ <h1>About</h1>
2
+
3
+ <h3>About me</h3>
4
+ <p>Write an introduction about yourself.</p>
5
+
6
+ <h3>About this site</h3>
7
+ <p>What do you want to show on your site/blog.</p>
8
+
9
+ <h3>Contact</h3>
10
+ <a href="https://github.com/YOU" target="_blank">GitHub</a>|
11
+ <a href="https://twitter.com/YOU_" target="_blank">Twitter</a>|
12
+ <a href="https://linkedin.com/in/YOU" target="_blank">Linkedin</a>|
13
+ <a href="https://t.me/YOU" target="_blank">Telegram</a>|
14
+ <a href="mailto:YOU@MAIL.com" target="_blank">Email</a>
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <% @author = "Your name" %>
5
+ <title><%= "#{@title_prefix} #{@author}"%></title>
6
+ <meta name="viewport" content="width=device-width,initial-scale=1">
7
+ <%= csrf_meta_tags %>
8
+ <%= csp_meta_tag %>
9
+
10
+ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
11
+ <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
12
+ </head>
13
+
14
+ <body>
15
+ <header class="header">
16
+ <div class="header-inner">
17
+ <a href="/" class="title"><%= @author %></a>
18
+ <nav class="nav">
19
+ <a class="link" href="<%= about_path %>">About</a>
20
+ <a class="link" href="<%= blog_path %>">Blog</a>
21
+ </nav>
22
+ </div>
23
+ </header>
24
+ <div class="content">
25
+ <%= yield %>
26
+ </div>
27
+ </body>
28
+ </html>
@@ -0,0 +1,8 @@
1
+ Rails.application.routes.draw do
2
+ get "blog", to: "blog#index"
3
+ get "blog/posts/:id", to: "blog#show", as: :blog_post
4
+
5
+ get "about", to: "home#index"
6
+
7
+ root "home#index"
8
+ end
data/lib/simpleblog.rb CHANGED
@@ -1,8 +1,16 @@
1
- require 'redcarpet'
2
- require 'rouge'
3
- require_dependency 'rouge/plugins/redcarpet'
1
+ require "redcarpet"
2
+ require "rouge"
3
+ require "rouge/plugins/redcarpet"
4
+ require "simpleblog/post"
5
+ require "simpleblog/railtie" if defined?(Rails) && defined?(Rails::Railtie)
4
6
 
5
- class ArticleHTMLRender < Redcarpet::Render::HTML
7
+ module SimpleBlogHelper
8
+ def set_site_prefix
9
+ @title_prefix = "#{params["controller"].capitalize} | "
10
+ end
11
+ end
12
+
13
+ class PostHTMLRender < Redcarpet::Render::HTML
6
14
  include Rouge::Plugins::Redcarpet
7
15
  include ActionView::Helpers::AssetTagHelper
8
16
 
@@ -14,28 +22,29 @@ class ArticleHTMLRender < Redcarpet::Render::HTML
14
22
  end
15
23
  end
16
24
  end
25
+
17
26
  class SimpleBlog
18
- def self.render_article(id)
19
- article_content = File.open("app/articles/#{id.to_i}.md").read
20
- markdown = Redcarpet::Markdown.new(ArticleHTMLRender, fenced_code_blocks: true)
27
+ def self.render_post(id)
28
+ post_content = File.open("app/posts/#{id.to_i}.md").read
29
+ markdown = Redcarpet::Markdown.new(PostHTMLRender, fenced_code_blocks: true)
21
30
 
22
- markdown.render(article_content)
31
+ markdown.render(post_content)
23
32
  end
24
33
 
25
- def self.list_articles(tag = "", in_progress: "true")
26
- articles_yml_result = YAML.load_file("app/articles/articles.yml")["articles"]
27
- articles = Article.build_list_of_articles(articles_yml_result)
34
+ def self.list_posts(tag = "", in_progress = "true")
35
+ posts_yml_result = YAML.load_file("app/posts/posts.yml")["posts"]
36
+ posts = Post.build_list_of_posts(posts_yml_result)
28
37
 
29
38
  if tag.present?
30
- articles = articles.filter { |article| article.tags.include?(tag) }
39
+ posts = posts.filter { |post| post.tags.include?(tag) }
31
40
  end
32
41
 
33
- if in_progress == "true"
34
- articles = articles.filter { |article| article.in_progress }
42
+ posts = if in_progress == "true"
43
+ posts.filter { |post| post.in_progress }
35
44
  else
36
- articles = articles.filter { |article| !article.in_progress }
45
+ posts.filter { |post| !post.in_progress }
37
46
  end
38
47
 
39
- articles.sort_by(&:id).reverse!
48
+ posts.sort_by(&:id).reverse!
40
49
  end
41
50
  end
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "simpleblog"
3
+ s.version = "1.0.1"
4
+ s.summary = "Helpers to generate markdown blog pages using Rails"
5
+ s.description = "Create a simple blog that can be edit with markdown"
6
+ s.authors = ["Caroline Salib"]
7
+ s.email = "carolinesalibc@gmail.com"
8
+ s.files = Dir.glob("{lib}/**/*")
9
+ s.files += ["simpleblog.gemspec"]
10
+ s.bindir = "exe"
11
+ s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
12
+ s.require_paths = ["lib"]
13
+ s.homepage = "https://rubygems.org/gems/simpleblog"
14
+ s.metadata = {"source_code_uri" => "https://github.com/carolinesalib/simpleblog"}
15
+ s.license = "MIT"
16
+
17
+ s.add_runtime_dependency "redcarpet"
18
+ s.add_runtime_dependency "rouge"
19
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caroline Salib
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-06-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rouge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description: Create a simple blog that can be edit with markdown
14
42
  email: carolinesalibc@gmail.com
15
43
  executables: []
@@ -17,10 +45,29 @@ extensions: []
17
45
  extra_rdoc_files: []
18
46
  files:
19
47
  - lib/simpleblog.rb
48
+ - lib/simpleblog/post.rb
49
+ - lib/simpleblog/railtie.rb
50
+ - lib/simpleblog/rake.rb
51
+ - lib/simpleblog/template/app/assets/stylesheets/blog.scss
52
+ - lib/simpleblog/template/app/assets/stylesheets/layouts/application.scss
53
+ - lib/simpleblog/template/app/assets/stylesheets/rouge.scss.erb
54
+ - lib/simpleblog/template/app/controllers/blog_controller.rb
55
+ - lib/simpleblog/template/app/controllers/home_controller.rb
56
+ - lib/simpleblog/template/app/helpers/blog_helper.rb
57
+ - lib/simpleblog/template/app/posts/1.md
58
+ - lib/simpleblog/template/app/posts/2.md
59
+ - lib/simpleblog/template/app/posts/posts.yml
60
+ - lib/simpleblog/template/app/views/blog/index.html.erb
61
+ - lib/simpleblog/template/app/views/blog/show.html.erb
62
+ - lib/simpleblog/template/app/views/home/index.html.erb
63
+ - lib/simpleblog/template/app/views/layouts/application.html.erb
64
+ - lib/simpleblog/template/config/routes.rb
65
+ - simpleblog.gemspec
20
66
  homepage: https://rubygems.org/gems/simpleblog
21
67
  licenses:
22
68
  - MIT
23
- metadata: {}
69
+ metadata:
70
+ source_code_uri: https://github.com/carolinesalib/simpleblog
24
71
  post_install_message:
25
72
  rdoc_options: []
26
73
  require_paths:
@@ -39,6 +86,5 @@ requirements: []
39
86
  rubygems_version: 3.2.32
40
87
  signing_key:
41
88
  specification_version: 4
42
- summary: Simpler than a regular Rails blog and more dynamically customizable than
43
- a Jekyll blog
89
+ summary: Helpers to generate markdown blog pages using Rails
44
90
  test_files: []