Sha256: 51d400e8a4216ef6716f443e1dc93ca6b7fc80a4b2aa397ae60a76c2e006556c

Contents?: true

Size: 1008 Bytes

Versions: 20

Compression:

Stored size: 1008 Bytes

Contents

module KnifeCookbookDoc
  module BaseModel

    def top_level_description(section)
      (top_level_descriptions[section.to_s] || []).join("\n").gsub(/\n+$/m,"\n")
    end

    def top_level_descriptions
      @top_level_descriptions ||= {}
    end

    def short_description
      unless @short_description
        @short_description = first_sentence(top_level_description('main'))
      end
      @short_description
    end

    private

    def first_sentence(string)
      string.gsub(/^(.*?\.(\z|\s))/m) do |match|
        return $1.gsub("\n",' ').strip
      end
      return nil
    end

    def extract_description
      description = []
      IO.read(@filename).gsub(/^=begin *\n *\# ?\<\n(.*?)^ *\# ?\>\n=end *\n/m) do
        description << $1
        ""
      end.gsub(/^ *\# ?\<\n(.*?)^ *\# ?\>\n/m) do
        description << $1.gsub(/^ *\# ?/, '')
        ""
      end.gsub(/^ *\# ?\<\> (.*?)$/) do
        description << $1
        ""
      end
      description.join("\n")
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
knife-cookbook-doc-0.31.1 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.31.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.30.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.29.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.28.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.27.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.26.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.25.2 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.24.2 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.25.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.24.1 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.24.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.23.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.22.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.21.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.20.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.19.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.18.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.17.0 lib/knife_cookbook_doc/base_model.rb
knife-cookbook-doc-0.16.0 lib/knife_cookbook_doc/base_model.rb