Sha256: eab2acb5c87be79082733377e6c4bb6270ca8d6fc4f2cdc0415209583a35ee8f

Contents?: true

Size: 760 Bytes

Versions: 2

Compression:

Stored size: 760 Bytes

Contents

module SectionsRails
  module Helpers

    # Returns a list of all section names in the given text.
    #
    # @param [ String ] text
    # @return [ Array<String> ]
    def find_sections text

      # Find sections in ERB templates.
      result = text.scan(/<%=\s*section\s+['":]([^'",\s]+)/).flatten.sort.uniq

      # Find sections in HAML templates.
      result.concat text.scan(/^\s*\=\s*section\s+['":]([^'",\s]+)/).flatten.sort.uniq

      result
    end

    # Returns directory and filename portion of the given path.
    #
    # @param [ String ] paths
    # @return [ Array<String, String> ]
    def split_path paths
      dirname = File.dirname(paths)
      dirname = '' if dirname == '.'
      [dirname, File.basename(paths)]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sections_rails-0.6.3 lib/sections_rails/helpers.rb
sections_rails-0.6.2 lib/sections_rails/helpers.rb