Sha256: 8587a33b951869791cff6f8641f7edf3e9d78e71b17c5cd89c9ab9a44b938039

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

Contents

require 'base64'

module Writefully
  module Source

    class << self
      def content_path
        Writefully.options[:content]
      end

      def models_path
        File.join(Writefully.options[:app_directory], 'app', 'models')
      end

      def sample_content file
        open(File.dirname(__FILE__) + "/../sample/#{file}").read
      end

      def sample_content_paths 
        valid_resources.map do |resource|
          ["#{resource}/1-change-me/README.md", 
           "#{resource}/1-change-me/meta.yml", 
           "#{resource}/1-change-me/assets/writefully.png"]
        end.flatten
      end

      def sample_content_properties file
        { 
          path: file,
          content: sample_content(file),
          message: "added sample #{file}"
        }
      end

      def valid_resources
        skim_for(::Regexp.new('Writefully::Post')).map { |r| r.pluralize }
      end

      def to_load
        skim_for ::Regexp.new('Writefully')
      end

      def skim_for matcher
        Dir.chdir(models_path) do 
          Dir.glob('*').select do |file|
            open(File.join(models_path, file)).read.strip.match(matcher) if File.file?(file)
          end.collect { |file| file.split('.')[0] }
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
writefully-0.8.2 lib/writefully/source.rb
writefully-0.8.1 lib/writefully/source.rb
writefully-0.8.0 lib/writefully/source.rb
writefully-0.7.1 lib/writefully/source.rb
writefully-0.6.12 lib/writefully/source.rb
writefully-0.6.11 lib/writefully/source.rb
writefully-0.6.10 lib/writefully/source.rb
writefully-0.6.9 lib/writefully/source.rb
writefully-0.6.7 lib/writefully/source.rb
writefully-0.6.6 lib/writefully/source.rb
writefully-0.6.5 lib/writefully/source.rb
writefully-0.6.4 lib/writefully/source.rb
writefully-0.6.3 lib/writefully/source.rb
writefully-0.6.2 lib/writefully/source.rb
writefully-0.5.1 lib/writefully/source.rb
writefully-0.5.0 lib/writefully/source.rb
writefully-0.4.10 lib/writefully/source.rb
writefully-0.4.8 lib/writefully/source.rb
writefully-0.4.7 lib/writefully/source.rb
writefully-0.4.6 lib/writefully/source.rb