Skip to content

Commit b9bfcd0

Browse files
authored
Merge pull request #390 from basecamp/markdown-out
Markdown out
2 parents c5ad495 + 09e3223 commit b9bfcd0

File tree

17 files changed

+247
-0
lines changed

17 files changed

+247
-0
lines changed

AGENTS.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Agent Guidelines
2+
3+
## Testing Conventions
4+
5+
### Use Existing Fixtures
6+
Prefer using existing fixtures over creating new records in tests. For example, use `leaves(:welcome_page)` instead of `books(:handbook).press Page.new(body: "..."), title: "..."`.
7+
8+
### URL Helpers in Tests
9+
Use `_path` helpers instead of `_url` helpers in controller/integration tests unless you need to test across different hosts or explicitly need the full URL.
10+
11+
**Preferred:**
12+
```ruby
13+
get book_slug_path(books(:handbook))
14+
```
15+
16+
**Avoid:**
17+
```ruby
18+
get book_slug_url(books(:handbook))
19+
```
20+
21+
### Response Body Assertions
22+
Use `assert_in_body` and `assert_not_in_body` to check if text is present or absent in the response body without DOM manipulation.
23+
24+
**Preferred:**
25+
```ruby
26+
assert_in_body "Expected content"
27+
assert_not_in_body "Unexpected content"
28+
```
29+
30+
**Avoid:**
31+
```ruby
32+
assert_includes response.body, "Expected content"
33+
assert_not_includes response.body, "Unexpected content"
34+
```
35+
36+
## Controller Conventions
37+
38+
### Simplified respond_to Blocks
39+
When using `respond_to` with default rendering, omit the `{ render }` block as it's implied.
40+
41+
**Preferred:**
42+
```ruby
43+
def show
44+
respond_to do |format|
45+
format.html
46+
format.md
47+
end
48+
end
49+
```
50+
51+
**Avoid:**
52+
```ruby
53+
def show
54+
respond_to do |format|
55+
format.html { render }
56+
format.md { render }
57+
end
58+
end
59+
```

app/controllers/books_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def create
2323

2424
def show
2525
@leaves = @book.leaves.active.with_leafables.positioned
26+
27+
respond_to do |format|
28+
format.html
29+
format.md
30+
end
2631
end
2732

2833
def edit

app/controllers/leafables_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def create
1616
end
1717

1818
def show
19+
respond_to do |format|
20+
format.html
21+
format.md
22+
end
1923
end
2024

2125
def edit

app/models/book.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ class Book < ApplicationRecord
1212
def press(leafable, leaf_params)
1313
leaves.create! leaf_params.merge(leafable: leafable)
1414
end
15+
16+
def markable
17+
leaves.active.positioned.map { it.leafable.markable }.join("\n\n")
18+
end
1519
end

app/models/page.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def html_preview
1616
rendered_html(markdown_source.first(1024))
1717
end
1818

19+
def markable
20+
body.content.to_s
21+
end
22+
1923
private
2024
def plain_text
2125
html_body = rendered_html(markdown_source)

app/models/picture.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ class Picture < ApplicationRecord
44
has_one_attached :image do |attachable|
55
attachable.variant :large, resize_to_limit: [ 1500, 1500 ]
66
end
7+
8+
def markable
9+
caption
10+
end
711
end

app/models/section.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ class Section < ApplicationRecord
44
def searchable_content
55
body
66
end
7+
8+
def markable
9+
body
10+
end
711
end

app/views/books/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<% @layout_class = "book" %>
33

44
<% content_for :head do %>
5+
<%= tag.link rel: "alternate", type: "text/markdown", href: book_slug_path(@book, format: :md) %>
56
<%= tag.meta property: "og:title", content: @book.title %>
67
<%= tag.meta property: "og:description", content: @book.subtitle %>
78
<%= tag.meta property: "og:image", content: @book.cover.blank? ? asset_url("covers/cover-#{@book.theme}-og.png") : "#{root_url}#{url_for(@book.cover)}" %>

app/views/books/show.md.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "<%= @book.title %>"
3+
author: "<%= @book.author %>"
4+
url: "<%= book_slug_url(@book) %>"
5+
---
6+
7+
<%= raw @book.markable %>

app/views/leafables/show.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<% content_for(:title) { page_title(@leaf, @book) } %>
22

3+
<% content_for :head do %>
4+
<%= tag.link rel: "alternate", type: "text/markdown", href: leafable_slug_path(@leaf, format: :md) %>
5+
<% end %>
6+
37
<% content_for :header do %>
48
<%= render "leaves/header", book: @book, leaf: @leaf %>
59
<% end %>

0 commit comments

Comments
 (0)