File: guide.rb

package info (click to toggle)
ruby-friendly-id 5.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 436 kB
  • sloc: ruby: 3,248; makefile: 3
file content (24 lines) | stat: -rwxr-xr-x 832 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby

# This script generates the Guide.md file included in the Yard docs.

def comments_from path
  path = File.expand_path("../lib/friendly_id/#{path}", __FILE__)
  matches = File.read(path).match(/\n\s*# @guide begin\n(.*)\s*# @guide end/m)

  return if matches.nil?

  match = matches[1].to_s
  match.split("\n")
    .map { |x| x.sub(/^\s*#\s?/, "") } # Strip off the comment, leading whitespace, and the space after the comment
    .reject { |x| x =~ /^@/ }         # Ignore yarddoc tags for the guide
    .join("\n").strip
end

File.open(File.expand_path("../Guide.md", __FILE__), "w:utf-8") do |guide|
  ["../friendly_id.rb", "base.rb", "finders.rb", "slugged.rb", "history.rb",
    "scoped.rb", "simple_i18n.rb", "reserved.rb"].each do |file|
    guide.write comments_from file
    guide.write "\n"
  end
end