Skip to content

Commit 285e9bc

Browse files
committed
Add more content
1 parent 6201f6c commit 285e9bc

File tree

13 files changed

+61
-6
lines changed

13 files changed

+61
-6
lines changed

app/assets/stylesheets/application.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ h1 {
5858
background: #dee2e6;
5959
}
6060

61+
.programming-language-list-item .name {
62+
font-size: 20px;
63+
font-weight: bold;
64+
margin-bottom: 10px;
65+
}
66+
67+
.programming-language-list-item .tagline {
68+
font-style: italic;
69+
}
70+
6171
article p {
6272
font-size: 20px;
6373
line-height: 1.3;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
class ApplicationController < ActionController::Base
2+
helper_method :page_title
3+
4+
def page_title
5+
'Programming languages'
6+
end
27
end

app/controllers/programming_languages_controller.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,25 @@ def index
66
end
77

88
def show
9-
programming_language = ProgrammingLanguage.find!(params[:language])
9+
raise ActiveRecord::RecordNotFound unless programming_language?
1010

11+
# Render the file for the programming language
1112
render programming_language.slug
1213
end
14+
15+
private
16+
17+
def programming_language
18+
return nil unless params[:language].present?
19+
20+
ProgrammingLanguage.find(params[:language])
21+
end
22+
23+
def programming_language?
24+
programming_language.present?
25+
end
26+
27+
def page_title
28+
programming_language.try(:page_title) || super
29+
end
1330
end

app/models/programming_language.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,32 @@ def initialize(pathname)
5252
end
5353

5454
def slug
55+
# The filename for the template, extension(s) removed
5556
pathname.basename.to_s.split('.').first
5657
end
5758

5859
def path
5960
"/#{slug}"
6061
end
6162

62-
def name
63-
frontmatter_data['name']
63+
[
64+
'first_introduced',
65+
'name',
66+
'tagline',
67+
].each do |attribute|
68+
# attribute: Get the value of attribute from frontmatter_data
69+
define_method(attribute) do
70+
frontmatter_data[attribute]
71+
end
72+
73+
# attribute?: check if attribute is present?
74+
define_method("#{attribute}?") do
75+
send(attribute).present?
76+
end
6477
end
6578

66-
def first_introduced
67-
frontmatter_data['first_introduced']
79+
def page_title
80+
frontmatter_data['page_title'].presence || "The #{name} Progamming Language"
6881
end
6982

7083
def <=>(other)

app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<title>FrontmatterOnRailsDev</title>
4+
<title><%= page_title %></title>
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<%= csrf_meta_tags %>
77
<%= csp_meta_tag %>

app/views/programming_languages/assembly.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
name: Assembly
3+
tagline: Unleashing the Power of Bare Metal Brilliance.
34
first_introduced: 1947
45
---
56

app/views/programming_languages/c.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
name: C
3+
tagline: The Foundation of Modern Computing, C You at the Core.
34
first_introduced: 1972
45
---
56

app/views/programming_languages/crystal.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
name: Crystal
3+
tagline: Crystal Clear Code, Performance Unleashed.
34
first_introduced: 2014
45
---
56

app/views/programming_languages/index.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ ol.programming-language-list
55
li.programming-language-list-item
66
= link_to(programming_language.path) do
77
.name= programming_language.name
8+
.tagline= programming_language.tagline

app/views/programming_languages/lisp.html.slim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
name: Lisp
3+
tagline: Elegance in Parentheses, Power in Simplicity.
34
first_introduced: 1960
45
---
56

0 commit comments

Comments
 (0)