Class: Eucalypt::BlogArticle
- Inherits:
-
Thor
- Object
- Thor
- Eucalypt::BlogArticle
- Extended by:
- List
- Includes:
- Eucalypt::Blog::Helpers, Helpers, Helpers::Messages, Thor::Actions
- Defined in:
- lib/eucalypt/blog/namespaces/blog-article/cli/article.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods included from List
Class Method Details
.banner(task, namespace = false, subcommand = true) ⇒ Object
101 102 103 |
# File 'lib/eucalypt/blog/namespaces/blog-article/cli/article.rb', line 101 def self.(task, namespace = false, subcommand = true) "#{basename} blog #{task.formatted_usage(self, true, subcommand).split(':').join(' ')}" end |
Instance Method Details
#destroy(urltitle = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/eucalypt/blog/namespaces/blog-article/cli/article.rb', line 58 def destroy(urltitle = nil) directory = File.('.') if Eucalypt.app? directory return unless Gemfile.check(%w[front_matter_parser rdiscount], 'eucalypt blog setup', directory) markdown_base = File.join directory, 'app', 'views', 'blog', 'markdown' articles_path = File.join '**', (urltitle ? "#{urltitle}.md" : "*.md") articles = Dir[File.join markdown_base, articles_path] if articles.empty? Eucalypt::Error.no_articles return end Eucalypt::Error.delete_article_warning; puts asset_base = File.join directory, 'app', 'assets', 'blog' articles_hash = {} article_numbers = [] articles.each_with_index do |article, i| number = (i+1).to_s article_numbers << number identifier = article.split(markdown_base.gsub(/\/$/,'')<<?/).last.split('.md').first articles_hash[number.to_sym] = identifier title = FrontMatterParser::Parser.parse_file(article).front_matter['title'] puts "#{number.colorize(:bold)}: #{identifier}#{title ? " - #{title}" : ''}" end article_number = ask("\nEnter the number of the article to delete:", limited_to: article_numbers) article = articles_hash[article_number.to_sym] delete_article = ask Out.("Delete article #{article.colorize(:bold)}?"), limited_to: %w[y Y Yes YES n N No NO] return unless %w[y Y Yes YES].include? delete_article remove_file File.join(markdown_base, "#{article}.md") paths = article.rpartition ?/ Dir.chdir(File.join asset_base, paths.first) { FileUtils.rm_rf paths.last } Eucalypt::Blog::Helpers.send :clean_directory, asset_base Eucalypt::Blog::Helpers.send :clean_directory, markdown_base else Eucalypt::Error.wrong_directory end end |
#generate(urltitle) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/eucalypt/blog/namespaces/blog-article/cli/article.rb', line 42 def generate(urltitle) directory = File.('.') if Eucalypt.app? directory return unless Gemfile.check(%w[front_matter_parser rdiscount], 'eucalypt blog setup', directory) urltitle = Inflect.route(urltitle) if urltitle generator = Eucalypt::Generators::Blog.new generator.destination_root = directory generator.article(urltitle: urltitle) else Eucalypt::Error.wrong_directory end end |
#list ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/eucalypt/blog/namespaces/blog-article/cli/article.rb', line 24 def list directory = File.('.') if Eucalypt.app? directory return unless Gemfile.check(%w[front_matter_parser rdiscount], 'eucalypt blog setup', directory) generator = Eucalypt::Generators::Blog.new generator.destination_root = directory generator.list( [:tag], [:ascending] ? :ascending : :descending, {year: [:year], month: [:month], day: [:day]} ) else Eucalypt::Error.wrong_directory end end |