lib/appjam/generators/gist.rb in appjam-0.1.8.pre vs lib/appjam/generators/gist.rb in appjam-0.1.8.pre3

- old
+ new

@@ -19,11 +19,11 @@ val.nil? ? @#{attr} : @#{attr} = val end } end end - attr_rw :gist_name, :gist_description, :gist_id, :gist_body + attr_rw :gist_name, :gist_description, :gist_id, :gist_body def preview_gist(gid) uri = URI("https://gist.github.com/#{gid}.txt") http = Net::HTTP.new(uri.host, uri.port) if uri.scheme == 'https' http.use_ssl = true @@ -34,11 +34,11 @@ tempfile = Tempfile.new('gist') tempfile.puts(result) tempfile.close if system('which qlmanage') - system("qlmanage -c public.plain-text -p #{tempfile.path} >& /dev/null") + system("qlmanage -p #{tempfile.path} >& /dev/null") end end def download_gists(username, page=1) puts "-- Downloading page #{page} of gists --" @@ -58,21 +58,33 @@ download_gists(username, page+1) unless links.empty? end end end - def download_gist(gist_id) - puts "-- fetching gist --" - puts "#{gist_id}.git" - if File.directory?("Support/#{gist_id}") - `cd Support/#{gist_id} && git pull ; cd ..` - else - `git clone git://gist.github.com/#{gist_id}.git Support/#{gist_id}` + def download_gist(gist_id,git_category,gist_name) + puts "-- fetching gist [#{gist_name}] --" + # require 'uri' + # require 'yajl/http_stream' + # + # uri = URI.parse("http://gist.github.com/api/v1/json/#{gist_id}") + # Yajl::HttpStream.get(uri, :symbolize_keys => true) do |hash| + # + # end + if File.directory?("Support/#{git_category}/#{gist_name}") + `rm -rf Support/#{git_category}/#{gist_name}` end + `git clone git://gist.github.com/#{gist_id}.git Support/#{git_category}/#{gist_name} && rm -rf Support/#{git_category}/#{gist_name}/.git` + if system('which qlmanage') + system("qlmanage -p Support/#{git_category}/#{gist_name}/*.* >& /dev/null") + end end end - + + gist_name "singleton" + gist_id "https://gist.github.com/979981" + gist_description "Singletons in Objective C" + # Add this generator to our appjam Appjam::Generators.add_generator(:gist, self) # Define the source Gist root def self.source_root; File.expand_path(File.dirname(__FILE__)); end @@ -91,11 +103,48 @@ def in_app_root? File.exist?('Classes') end - def create_gist - + def create_git + if in_app_root? + valid_constant?(options[:gist] || name) + @gist_name = (options[:app] || name).gsub(/W/, "_").downcase + @class_name = (options[:app] || name).gsub(/W/, "_").capitalize + @xcode_project_name = File.basename(Dir.glob('*.xcodeproj')[0],'.xcodeproj').downcase + @developer = "eiffel" + @created_on = Date.today.to_s + self.destination_root = options[:root] + + require 'yaml' + g = YAML.load_file(File.expand_path(File.dirname(__FILE__) + '/gist.yml')) + g.each_pair {|key,value| + gcategory = key.downcase + g[key].each { |k| + k.each_pair { |k1,v1| + if "#{k1}" == @gist_name + gid = k[k1][0]['id'] + gname = k[k1][1]['name'].downcase + Gist::download_gist("#{gid}".to_i,gcategory,gname) + eval(File.read(__FILE__) =~ /^__END__/ && $' || '') + say "=================================================================" + say "Your '#{gname.capitalize}' design pattern snippet has been generated." + say "Check Support/#{gcategory}/#{gname}/ for Snippet" + say "Open #{@xcode_project_name.capitalize}.xcodeproj" + say "Add 'Support/#{gcategory}/#{gname}/' folder to the 'Classes/apps' Group" + say "Build and Run" + say "=================================================================" + end + } + } + } + else + puts + puts '-'*70 + puts "You are not in an iphone project folder" + puts '-'*70 + puts + end end end # Gist end # Generators end # Appjam