Sha256: 0c104b9e40c8c274e00850fb580a6483c242151820ed5c35d2d042b224989bc7

Contents?: true

Size: 1.76 KB

Versions: 9

Compression:

Stored size: 1.76 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2020 Eric Crane.  All rights reserved.
#
# Markdown data.
#
require 'tty-markdown'
require 'tty-pager'

module Gloo
  module Objs
    class Markdown < Gloo::Core::Obj

      KEYWORD = 'markdown'.freeze
      KEYWORD_SHORT = 'md'.freeze

      #
      # The name of the object type.
      #
      def self.typename
        return KEYWORD
      end

      #
      # The short name of the object type.
      #
      def self.short_typename
        return KEYWORD_SHORT
      end

      #
      # Set the value with any necessary type conversions.
      #
      def set_value( new_value )
        self.value = new_value.to_s
      end

      #
      # Does this object support multi-line values?
      # Initially only true for scripts.
      #
      def multiline_value?
        return false
      end

      #
      # Get the number of lines of text.
      #
      def line_count
        return value.split( "\n" ).count
      end

      # ---------------------------------------------------------------------
      #    Messages
      # ---------------------------------------------------------------------

      #
      # Get a list of message names that this object receives.
      #
      def self.messages
        return super + %w[show page]
      end

      #
      # Show the markdown data in the terminal.
      #
      def msg_show
        puts TTY::Markdown.parse self.value
      end

      #
      # Show the markdown data in the terminal, paginated.
      #
      def msg_page
        return unless self.value

        md = TTY::Markdown.parse self.value
        # pager = TTY::Pager::SystemPager.new command: 'less -R'
        pager = TTY::Pager.new
        pager.page( md )
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gloo-0.8.0 lib/gloo/objs/data/markdown.rb
gloo-0.7.7 lib/gloo/objs/data/markdown.rb
gloo-0.7.6 lib/gloo/objs/data/markdown.rb
gloo-0.7.5 lib/gloo/objs/data/markdown.rb
gloo-0.7.4 lib/gloo/objs/data/markdown.rb
gloo-0.7.3 lib/gloo/objs/data/markdown.rb
gloo-0.7.2 lib/gloo/objs/data/markdown.rb
gloo-0.7.1 lib/gloo/objs/data/markdown.rb
gloo-0.7.0 lib/gloo/objs/data/markdown.rb