珀龙:一个为 Ruby on Rails 设计的静态网站生成器
Perron: A Static Site Generator for Ruby on Rails

原始链接: https://perron-site.statichost.page/

```class Content::Article < Perron::Resource include Adjacency SECTIONS = { getting_started: "Getting started", content: "Content", metadata: "Metadata" }.with_indifferent_access def self.sections SECTIONS.map { |section_data| Section.new(key: section_data.first, name: section_data.second, resources: Content::Article.all.select { it.metadata.section == section_data.first }.sort_by(&:order)) } end delegate :section, :order, :title, :description, to: :metadata validates :title, :description, presence: true validates :section, inclusion: { in: SECTIONS } validates :order, numericality: { greater_than_or_equal_to: 1 } def article_section Section.new(key: metadata.section, name: SECTIONS[metadata.section], resources: Content::Article.all.select { it.metadata.section == metadata.section }.sort_by(&:order)) end private Section = Data.define(:key, :name, :resources) end``` ``` class Content::Article < Perron::Resource include Adjacency SECTIONS = { getting_started: "Getting started", content: "Content", metadata: "Metadata" }.with_indifferent_access def self.sections SECTIONS.map { |section_data| Section.new( key: section_data.first, name: section_data.second, resources: Content::Article.all.select { it.metadata.section == section_data.first }.sort_by(&:order) ) } end delegate :section, :order, :title, :description, to: :metadata validates :title, :description, presence: true validates :section, inclusion: { in: SECTIONS } validates :order, numericality: { greater_than_or_equal_to: 1 } def article_section Section.new( key: metadata.section, name: SECTIONS[metadata.section], resources: Content::Article.all.select { it.metadata.section == metadata.section }.sort_by(&:order) ) end private Section = Data.define(:key, :name, :resources) end ``` ``` class Content::Article < Perron::Resource include Adjacency SECTIONS = { getting_started: "Getting started", content: "Content", metadata: "Metadata" }.with_indifferent_access def self.sections SECTIONS.map do |section_data| Section.new( key: section_data.first, name: section_data.second, resources: Content::Article.all.select { |it| it.metadata.section == section_data.first }.sort_by(&:order) ) end end delegate :section, :order, :title, :description, to: :metadata validates :title, :description, presence: true validates :section, inclusion: { in: SECTIONS } validates :order, numericality: { greater_than_or_equal_to: 1 } def article_section Section.new( key: metadata.section, name: SECTIONS[metadata.section], resources: Content::Article.all.select { |it| it.metadata.section == metadata.section }.sort_by(&:order) ) end private Section = Data.define(:key, :name, :resources) end ``` ``` class Content::Article < Perron::Resource include Adjacency SECTIONS = { getting_started: "Getting started", content: "Content", metadata: "Metadata" }.with_indifferent_access def self.sections SECTIONS.map do |section_data| Section.new( key: section_data.first, name: section_data.second, resources: Content::Article.all.select { |it| it.metadata.section == section_data.first }.sort_by(&:order) ) end end delegate :section, :order, :title, :description, to: :metadata validates :title, :description, presence: true validates :section, inclusion: { in: SECTIONS } validates :order, numericality: { greater_than_or_equal_to: 1 } def article_section Section.new( key: metadata.section, name: SECTIONS[metadata.section], resources: Content::Article.all.select { |it| it.metadata.section == metadata.section }.sort_by(&:order) ) end private Section = Data.define(:key, :name, :resources) end ```

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Perron:Ruby on Rails 的静态站点生成器 (statichost.page) 4 点赞 Kerrick 1 小时前 | 隐藏 | 过去 | 收藏 | 讨论 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文
class Content::Article < Perron::Resource
  include Adjacency

  SECTIONS = {
    getting_started: "Getting started",
    content: "Content",
    metadata: "Metadata"
  }.with_indifferent_access

  def self.sections
    SECTIONS.map { |section_data| Section.new(key: section_data.first, name: section_data.second, resources: Content::Article.all.select { it.metadata.section == section_data.first }.sort_by(&:order)) }
  end

  delegate :section, :order, :title, :description, to: :metadata

  validates :title, :description, presence: true
  validates :section, inclusion: { in: SECTIONS }
  validates :order, numericality: { greater_than_or_equal_to: 1 }

  def article_section
    Section.new(key: metadata.section, name: SECTIONS[metadata.section], resources: Content::Article.all.select { it.metadata.section == metadata.section }.sort_by(&:order))
  end

  private

  Section = Data.define(:key, :name, :resources)
end

联系我们 contact @ memedata.com