lib/pry-theme/helper.rb in pry-theme-0.0.8 vs lib/pry-theme/helper.rb in pry-theme-0.0.9

- old
+ new

@@ -1,14 +1,48 @@ module PryTheme module Helper - def each_theme_in(dir, &block) - themes = Dir.entries(dir) - %w{ . .. } - n = themes.size + module_function - themes.each_with_index do |theme, index| - yield(theme, index, n) - end + def example_themes + (Dir.entries(EXAMPLES_ROOT) - %w{ . .. }) + end + + def installed_themes + (Dir.entries(THEME_DIR) - %w{ . .. }) + end + + def installed?(theme) + installed_themes.any? { |t| /\A#{theme}.prytheme\z/ =~ t } + end + + def lputs(text, out=nil) + Pry::Helpers::BaseHelpers.stagger_output(text, out) + end + + def make_bold(text) + Pry::Helpers::Text.bold(text) + end + + def theme_file_version(path) + version = File.foreach(path) { |line| break line if $. == 4 } + version.scan(/\d+/)[0].to_i + end + + def default_theme(name) + File.join(EXAMPLES_ROOT, name) + end + + def local_theme(name) + File.join(THEME_DIR, name) + end + + def fetch_collection(path, &block) + uri = URI.parse(COLLECTION + path) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + + yield(http, uri) end end end