1+ require_relative 'lib/madness'
2+ require "sasstool"
3+ require "slim"
4+ require "pretty_trace/enable-trim"
5+ require "runfile-tasks"
6+
7+ title "Madness Runfile"
8+ summary "Runfile tasks for building the Madness gem"
9+ version Madness::VERSION
10+
11+ RunfileTasks::RubyGems.all 'madness'
12+ RunfileTasks::Testing.rspec
13+
14+ help "Generate public CSS"
15+ usage 'css [--watch]'
16+ option '-w, --watch', 'Watch for changes and regenerate'
17+ action :css do |args|
18+ if args['--watch']
19+ exec "filewatcher --immediate 'app/styles/*.scss' 'bundle exec run css'"
20+ else
21+ target = "app/public/css"
22+ Sasstool::Renderer.new("app/styles/main.scss").save target
23+ puts "Saved #{target}"
24+ end
25+ end
26+
27+ usage "(server|s) [--sample]"
28+ help "Run server with spec docroot or the sample docroot"
29+ option "-s, --sample", "Use the 'sample' folder instead of the fixture"
30+ action :server, :s do |args|
31+ folder = args['--sample'] ? 'sample' : 'spec/fixtures/docroot'
32+ system "bundle exec bin/madness #{folder}"
33+ end
34+
35+ help 'Extract fontello zip'
36+ action :fontello do
37+ system 'mkdir -p tmp/fontello'
38+ zip = 'assets/fontello.zip'
39+ system "unzip -j -o #{zip} -d tmp/fontello"
40+ %w[eot svg ttf woff woff2].each do |ext|
41+ system "cp tmp/fontello/fontello.#{ext} app/public/font/"
42+ end
43+
44+ system 'cp tmp/fontello/fontello.css app/styles/_fontello.scss'
45+ end
46+
47+ help "Generate changelog and append old changelog"
48+ action :changelog do
49+ system "git changelog --save"
50+ # append older changelog (prior to switching to git-changelog)
51+ system "cat .changelog.old.md >> CHANGELOG.md"
52+ end
53+
54+ help "Count lines of code"
55+ action :cloc do
56+ system "cloc . --exclude-dir coverage,spec,examples"
57+ end
58+
59+ help "Generate the screenshots animated gif"
60+ action :screenshots do
61+ puts "Saving assets/screenshots.gif"
62+ exec "convert -delay 300 -loop 0 assets/screenshots/*.png assets/screenshots.gif"
63+ end
64+
65+ help "Generate the site to /docs"
66+ action :site do
67+ # Use the README as a base, and do some TOC acrobatics to prevent the HTML
68+ # generator from converting some TOC comments.
69+ readme = File.read('README.md')
70+ .gsub('<!-- TOC -->', '{{TOC_COMMENT}}')
71+ .gsub('<!-- MADNESS_TOC -->', '<!-- TOC -->')
72+ .sub(/\[!\[Gem Version\].*/, '')
73+ .sub(/\[!\[Build Status\].*/, '')
74+ .sub(/\[!\[Maintainability\].*/, '')
75+
76+ # Create the Madness page using Madness
77+ content = Madness::MarkdownDocument.new(readme)
78+ .to_html
79+ .gsub '{{TOC_COMMENT}}', '<!-- TOC -->'
80+
81+ # Place the rendered HTML inside a slim template
82+ Slim::Engine.set_options pretty: true
83+ html = Slim::Template.new("assets/site/index.slim").render(nil, content: content)
84+
85+ # Export for GitHub pages
86+ File.write 'docs/index.html', html
87+ puts 'Saved docs/index.html'
88+ end
89+
90+ require_relative 'debug.rb' if File.exist? 'debug.rb'
0 commit comments