### Resource Association Content Example Source: https://context7.com/rails-designer/perron/llms.txt Shows how to define resource associations in markdown content using foreign keys. This allows Perron to establish relationships between different content pieces, like linking a post to its author and category. ```markdown --- # app/content/posts/my-post.md title: My Post author_id: john-doe category_id: tutorials tag_ids: [ruby, rails, web-development] --- ``` -------------------------------- ### Example Feature Partial for Data Rendering Source: https://github.com/rails-designer/perron/blob/main/test/dummy/app/content/data/README.md This is an example of a partial file (`_feature.html.erb`) that Perron renders for each item in a 'features' data collection. It defines the structure for displaying individual feature data. ```erb

<%= feature.name %>

<%= feature.description %>

``` -------------------------------- ### Install Perron Gem and Markdown Parser in Rails Source: https://context7.com/rails-designer/perron/llms.txt This snippet shows how to add the Perron gem to your Rails project's Gemfile and install a markdown parser. Ensure you run `bundle install` and then generate Perron's initial configuration files. ```ruby # Gemfile gem 'perron' # Add markdown parser (choose one) gem 'commonmarker' # or 'kramdown' or 'redcarpet' ``` ```bash bundle install rails generate perron:install ``` -------------------------------- ### Build Static Site Programmatically Source: https://context7.com/rails-designer/perron/llms.txt Illustrates how to build, validate, and manage the static site generation process programmatically using Perron's Ruby API. This includes options for automatic builds during asset precompilation. ```ruby # Programmatic build Perron::Site.build # Validate all resources Perron::Site.validate # In integrated mode, builds automatically during asset precompilation rails assets:precompile # also builds Perron site ``` -------------------------------- ### Implement Posts Controller for Content Display Source: https://context7.com/rails-designer/perron/llms.txt This controller code demonstrates how to fetch and display blog posts using Perron's `Content::Post` resource. It includes actions for listing all posts and showing a single post by its ID. ```ruby # app/controllers/content/posts_controller.rb class Content::PostsController < ApplicationController def index @posts = Content::Post.all end def show @post = Content::Post.find(params[:id]) end end ``` -------------------------------- ### Create Markdown Content for a Post Source: https://context7.com/rails-designer/perron/llms.txt This markdown file represents a blog post, including front matter for metadata (title, description, author, publication date, image) and the main content written in markdown. ```markdown --- # app/content/posts/2024-01-15-my-first-post.md title: My First Post description: Introduction to Perron static site generation author_id: john-doe editor_id: editor-1 published_at: 2024-01-15 10:00:00 image: /images/posts/first-post.jpg --- # Welcome to My Blog This is my first post using **Perron**. The content is written in markdown and supports all standard markdown features. ## Features - Easy to write - Rails conventions - Static output ``` -------------------------------- ### Configure Rails Routes for Content Posts Source: https://context7.com/rails-designer/perron/llms.txt This snippet sets up routes in a Rails application to handle blog posts. It maps the root URL to the posts index and defines routes for individual posts under the '/blog' path. ```ruby # config/routes.rb Rails.application.routes.draw do resources :posts, path: "blog", module: :content, only: [:index, :show] root to: "content/posts#index" end ``` -------------------------------- ### Build Static Site with Rails Perron Commands Source: https://context7.com/rails-designer/perron/llms.txt Provides command-line interface (CLI) commands for building, validating, and cleaning the static site generated by Perron. These commands are executed via the Rails Rake tasks. ```bash # Build static site rails perron:build # Validate content before building rails perron:validate # Clean output directory rails perron:clobber ``` -------------------------------- ### Access and Query Perron Content Collections Source: https://context7.com/rails-designer/perron/llms.txt This code illustrates how to programmatically access and query content resources managed by Perron. It shows fetching all posts, finding a specific post by its slug, listing available collections, and accessing resource metadata like title, content, and reading time. ```ruby # Get all published posts posts = Perron::Site.collection("posts").all # or using resource class posts = Content::Post.all # Find specific post by slug post = Perron::Site.collection("posts").find("my-first-post") # or post = Content::Post.find("my-first-post") # Get all collections collections = Perron::Site.collections collections.each do |collection| puts collection.name puts collection.resources.count end # Access resource metadata post = Content::Post.find("my-first-post") post.title # => "My First Post" post.description # => "Introduction to..." post.published_at # => 2024-01-15 10:00:00 post.slug # => "my-first-post" post.content # => rendered markdown/erb content # Find related resources post.related_resources(limit: 3) # Get reading time post.reading_time # => "5 min read" ``` -------------------------------- ### Render Markdown in Rails Views Source: https://context7.com/rails-designer/perron/llms.txt Demonstrates how to render markdown content within Rails views using the `markdownify` helper. This helper can process markdown with optional HTML processors for enhanced rendering like target blank links, lazy-loaded images, and syntax highlighting. ```erb <%= meta_tags %> <%= feeds %>

<%= @post.title %>

<%= @post.reading_time %>
<%= markdownify @post.content %>
<%= markdownify @post.content, process: [:target_blank, :lazy_load_images, :syntax_highlight] %> <%= markdownify process: [:target_blank] do %> ## Custom Markdown This is **inline** markdown content that will be processed. [External link](https://example.com) <% end %>
``` -------------------------------- ### Accessing Associated Resources in Rails Source: https://context7.com/rails-designer/perron/llms.txt Demonstrates how to access associated resources (e.g., author, category, tags) of a `Content::Post` object in Rails. It also shows how to retrieve all posts associated with a specific author. ```ruby post = Content::Post.find("my-post") post.author # => Content::Author instance post.author.name # => "John Doe" post.category # => Content::Category instance post.tags # => Array of Content::Tag instances author = Content::Author.find("john-doe") author.posts # => All posts by this author ``` -------------------------------- ### Access Data Attributes in Ruby Source: https://github.com/rails-designer/perron/blob/main/test/dummy/app/content/data/README.md Illustrates the supported methods for accessing attributes of individual data records within Ruby code. Both dot notation and hash-like key access are demonstrated for flexibility. ```ruby feature.name feature[:name] ``` -------------------------------- ### Create Custom HTML Processor for YouTube Embeds Source: https://context7.com/rails-designer/perron/llms.txt Defines a custom HTML processor that extends Perron's markdown rendering capabilities. This processor specifically targets YouTube links and replaces them with embedded YouTube iframes, enhancing media integration. ```ruby # app/processors/custom_embed_processor.rb class CustomEmbedProcessor < Perron::HtmlProcessor::Base def process document.css('a[href*="youtube.com"]').each do |link| video_id = extract_video_id(link['href']) iframe = create_youtube_embed(video_id) link.replace(iframe) end end private def extract_video_id(url) url[/(?:v=|\/)([\w-]+)/, 1] end def create_youtube_embed(video_id) <<~HTML
HTML end end ``` -------------------------------- ### Configure Perron Static Site Generator Source: https://context7.com/rails-designer/perron/llms.txt This code configures Perron's behavior within a Rails initializer. It sets site metadata, build mode, output directory, URL options, markdown parser, sitemap, and metadata formatting. ```ruby # config/initializers/perron.rb Perron.configure do |config| config.site_name = "My Blog" config.site_description = "A Rails-powered static blog" config.mode = :standalone # or :integrated config.output = "output" # output directory config.default_url_options = { host: "example.com", protocol: "https", trailing_slash: true } config.markdown_parser = :commonmarker config.markdown_options = { parse: { smart: true }, render: { hardbreaks: false } } config.sitemap.enabled = true config.sitemap.priority = 0.5 config.sitemap.change_frequency = :monthly config.metadata.title_separator = " — " config.metadata.title_suffix = "My Blog" end ``` -------------------------------- ### SEO Metadata Frontmatter Source: https://context7.com/rails-designer/perron/llms.txt Defines SEO metadata for a content file using YAML frontmatter. This includes titles, descriptions, open graph tags, Twitter card type, and canonical URLs, which are used to generate meta tags for SEO and social sharing. ```markdown --- title: Complete Guide to Rails description: Learn Rails from scratch in this comprehensive guide og_title: Rails Guide - Complete Tutorial og_description: Master Ruby on Rails web development og_image: https://example.com/images/rails-guide.jpg twitter_card: summary_large_image canoical_url: https://example.com/guides/rails --- ``` -------------------------------- ### Embed Ruby in Markdown Content Source: https://context7.com/rails-designer/perron/llms.txt Demonstrates using embedded Ruby (ERB) within markdown files for dynamic content generation. Supports frontmatter for metadata and ERB tags for embedding Ruby code, such as variable interpolation, conditionals, and loops. ```markdown --- # app/content/pages/dynamic-page.md title: Dynamic Page erb: true --- # <%= @title %> Current year: <%= Date.current.year %> <% if user_signed_in? %> Welcome back, <%= current_user.name %>! <% end %> <%= link_to "Home", root_path %> <% data = Content::Data::Stats.all %> <% data.each do |stat| %> - <%= stat.label %>: <%= stat.value %> <% end %> ``` -------------------------------- ### Use Custom HTML Processor in Rails Views Source: https://context7.com/rails-designer/perron/llms.txt Illustrates how to apply a custom HTML processor, such as `CustomEmbedProcessor`, when rendering markdown content in Rails views. This allows for flexible and extended markdown processing beyond the default capabilities. ```erb <%= markdownify @content, process: [:target_blank, CustomEmbedProcessor] %> ``` -------------------------------- ### Define a Perron Content Resource Source: https://context7.com/rails-designer/perron/llms.txt This Ruby code defines a content resource named 'Post' that inherits from `Perron::Resource`. It establishes associations and configures specific metadata and feed generation for this resource type. ```ruby # app/models/content/post.rb class Content::Post < Perron::Resource belongs_to :author belongs_to :editor, class_name: "Content::Data::Editors" configure do |config| config.sitemap.enabled = true config.metadata.author = "Blog Team" config.metadata.type = "article" config.feeds.rss.enabled = true config.feeds.rss.path = "blog/feed.xml" end end ``` -------------------------------- ### Render SEO Meta Tags in Layout Source: https://context7.com/rails-designer/perron/llms.txt Renders SEO meta tags and feed links within a Rails application's layout file. It supports rendering all meta tags, specific tags using `only`, or excluding tags using `except`. ```erb <%= meta_tags %> <%= meta_tags only: [:title, :description, :og_title, :og_image] %> <%= meta_tags except: [:twitter_card] %> <%= feeds %> <%= feeds only: [:posts] %> <%= feeds except: [:pages] %> ``` -------------------------------- ### Configure SEO Metadata in Rails Model Source: https://context7.com/rails-designer/perron/llms.txt Configures SEO and social sharing metadata for a Rails Content::Post model. This involves setting author, type, and other metadata properties that can be later rendered in the application's views. ```ruby class Content::Post < Perron::Resource configure do |config| config.metadata.author = "Blog Team" config.metadata.type = "article" end end ``` -------------------------------- ### Render Data Collections with Partials in ERB Source: https://github.com/rails-designer/perron/blob/main/test/dummy/app/content/data/README.md Shows how to directly render a collection of data items using Rails-like partial rendering. Perron automatically iterates through the collection and renders a specified partial for each item. ```erb <%= render Perron::Site.data.features %> ``` -------------------------------- ### Load Developer Data Source: https://context7.com/rails-designer/perron/llms.txt Loads all developer data from the Content::Data::Team::Developers model. The data is expected to be in a JSON format, with each object representing a developer and their attributes like ID, name, role, and skills. ```ruby developers = Content::Data::Team::Developers.all ``` -------------------------------- ### Configure RSS and JSON Feeds in Rails Model Source: https://context7.com/rails-designer/perron/llms.txt Configures RSS and JSON feeds for a Rails model using Perron's `configure` block. Specifies feed paths, titles, descriptions, and limits. This feature automatically generates feed files during the build process. ```ruby class Content::Post < Perron::Resource configure do |config| config.feeds.rss.enabled = true config.feeds.rss.path = "blog/feed.xml" config.feeds.rss.title = "My Blog RSS Feed" config.feeds.rss.description = "Latest posts from my blog" config.feeds.rss.limit = 20 config.feeds.json.enabled = true config.feeds.json.path = "blog/feed.json" config.feeds.json.limit = 20 end end ``` -------------------------------- ### Embed ERB Content within Markdown Source: https://context7.com/rails-designer/perron/llms.txt Shows how to use the `erbify` helper within a markdown file to embed dynamically generated ERB content. This allows for the inclusion of Rails helpers like `link_to` and `image_tag` within markdown content. ```erb --- title: Mixed Content --- ## Post Title Regular markdown content here. <%= erbify do %> <%= link_to "Dynamic Link", some_path %> <%= image_tag "photo.jpg" %> <% end %> More markdown content continues... ``` -------------------------------- ### Access Structured Data Files in Rails Source: https://context7.com/rails-designer/perron/llms.txt This Ruby code demonstrates how to access structured data loaded from YAML files using auto-generated classes provided by Perron. It shows how to retrieve all records from a data collection or find a specific record by its ID and access its attributes. ```ruby # Access data using auto-generated classes authors = Content::Data::Authors.all author = Content::Data::Authors.find("john-doe") author.name # => "John Doe" author.email # => "john@example.com" author.bio # => "Senior Rails developer" ``` -------------------------------- ### Define Structured Data for Authors Source: https://context7.com/rails-designer/perron/llms.txt This YAML file defines structured data for authors, including their ID, name, email, bio, and avatar path. This data can be accessed and utilized within the Rails application through Perron's data layer. ```yaml # app/content/data/authors.yml - id: john-doe name: John Doe email: john@example.com bio: Senior Rails developer avatar: /images/authors/john.jpg - id: jane-smith name: Jane Smith email: jane@example.com bio: Content strategist ``` -------------------------------- ### Define Resource Associations in Rails Source: https://context7.com/rails-designer/perron/llms.txt Defines relationships between different content resources in a Rails application using `belongs_to` and `has_many` associations. This allows for easy navigation and retrieval of related content objects. ```ruby class Content::Post < Perron::Resource belongs_to :author belongs_to :category has_many :tags end # app/models/content/author.rb class Content::Author < Perron::Resource has_many :posts end ``` -------------------------------- ### Render Dynamic Resource Information with ERB Source: https://github.com/rails-designer/perron/blob/main/test/dummy/app/content/posts/2025-10-01-inline-erb-post.md This snippet demonstrates how to embed ERB code within a post to dynamically generate content. It utilizes the `erbify` helper and accesses resource attributes like `slug` and author metadata. Ensure the `@resource` object is available in the context for this to work correctly. ```erb <%= erbify do %> The slug for this resource is: <%= @resource.slug %> and is it authored by <%= @resource.metadata.author %> <% end %> ``` -------------------------------- ### Iterate Over Data Collection in ERB Source: https://github.com/rails-designer/perron/blob/main/test/dummy/app/content/data/README.md This snippet demonstrates how to access and iterate over a data collection (e.g., 'features') loaded by Perron within an ERB template. It assumes the data is available via Perron::Site.data. ```erb <% Perron::Site.data.features.each do |feature| %>

<%= feature.name %>

<%= feature.description %>

<% end %> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.