Skip to content

Commit

Permalink
added stimulus controller
Browse files Browse the repository at this point in the history
  • Loading branch information
SyedMSawaid committed Jan 24, 2025
1 parent 83a60d2 commit b29bfd6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions frontend/javascript/controllers/reading_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
console.log("Hello, Stimulus!", this.element)
}
}
8 changes: 8 additions & 0 deletions plugins/builders/books.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def build
def add_layout_to_book_chapters
site.collections.books.resources.each do |chapter|
chapter.data.layout = "default"
chapter.content = "#{chapter.content}\n#{stimulus_controller("reading", values: {chapter: 1})}"
end
end

Expand Down Expand Up @@ -38,4 +39,11 @@ def create_chapters_list_for(book)
</ul>
HTML
end

def stimulus_controller(name, values: {})
values = values.map { |k, v| "data-#{name}-#{k}-value='#{v}'" }.join(", ")
<<-HTML
<div data-controller='#{name}' #{values}></div>
HTML
end
end
3 changes: 2 additions & 1 deletion src/_books/book-one/01-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
title: "Introduction"
---

This is how it works
# This is how it works
Are you sure?
2 changes: 1 addition & 1 deletion src/books.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: default
---
<h1>HI BRo</h1>

<ul>
<ul data-controller="bookmark">
<% book_names = book_ids = site.collections.books.resources.map {
|b| b.id.split("_books/").last.split("/").first.titlecase
}.uniq %>
Expand Down

0 comments on commit b29bfd6

Please sign in to comment.