simpleblog 0.0.3 → 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: '088b308bbac1b09cf39028ce6e7cd438634e9107b0e6263c6ff68ef35648f7b3'
4
- data.tar.gz: 89509d5c451581870e81819476438e7ee108d382e9496405887c6787441c55f3
3
+ metadata.gz: ab03e15d27ae35ba6d80a517e49038cc3a1371b517149731914788a89961baab
4
+ data.tar.gz: c970ef75bae07476a32c94e978c40751e839a26ea980f00a55e97f3533b9aa09
5
5
  SHA512:
6
- metadata.gz: f323bb4c1d992f28c31f8bcbc295ddfe39286c480ee9d0aea758da653b85c36619f8ff013f3f8f742d7665220e746bf2451e93fcfcd577cab8cd04621f929269
7
- data.tar.gz: 7a86041cd1ea148e4888be3e60f8389d34fbe674e85253843e6c501be9ec037ba99073d327bae84d29992a8c46401b565d4570b2882b429a2cebb320c1f76cde
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,9 +1,16 @@
1
1
  require "redcarpet"
2
2
  require "rouge"
3
+ require "rouge/plugins/redcarpet"
4
+ require "simpleblog/post"
5
+ require "simpleblog/railtie" if defined?(Rails) && defined?(Rails::Railtie)
3
6
 
4
- require_dependency "rouge/plugins/redcarpet"
7
+ module SimpleBlogHelper
8
+ def set_site_prefix
9
+ @title_prefix = "#{params["controller"].capitalize} | "
10
+ end
11
+ end
5
12
 
6
- class ArticleHTMLRender < Redcarpet::Render::HTML
13
+ class PostHTMLRender < Redcarpet::Render::HTML
7
14
  include Rouge::Plugins::Redcarpet
8
15
  include ActionView::Helpers::AssetTagHelper
9
16
 
@@ -17,27 +24,27 @@ class ArticleHTMLRender < Redcarpet::Render::HTML
17
24
  end
18
25
 
19
26
  class SimpleBlog
20
- def self.render_article(id)
21
- article_content = File.open("app/articles/#{id.to_i}.md").read
22
- 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)
23
30
 
24
- markdown.render(article_content)
31
+ markdown.render(post_content)
25
32
  end
26
33
 
27
- def self.list_articles(tag = "", in_progress = "true")
28
- articles_yml_result = YAML.load_file("app/articles/articles.yml")["articles"]
29
- 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)
30
37
 
31
38
  if tag.present?
32
- articles = articles.filter { |article| article.tags.include?(tag) }
39
+ posts = posts.filter { |post| post.tags.include?(tag) }
33
40
  end
34
41
 
35
- articles = if in_progress == "true"
36
- articles.filter { |article| article.in_progress }
42
+ posts = if in_progress == "true"
43
+ posts.filter { |post| post.in_progress }
37
44
  else
38
- articles.filter { |article| !article.in_progress }
45
+ posts.filter { |post| !post.in_progress }
39
46
  end
40
47
 
41
- articles.sort_by(&:id).reverse!
48
+ posts.sort_by(&:id).reverse!
42
49
  end
43
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simpleblog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
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-04-17 00:00:00.000000000 Z
11
+ date: 2022-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
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'
27
41
  description: Create a simple blog that can be edit with markdown
28
42
  email: carolinesalibc@gmail.com
29
43
  executables: []
@@ -31,6 +45,24 @@ extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
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
34
66
  homepage: https://rubygems.org/gems/simpleblog
35
67
  licenses:
36
68
  - MIT