laravel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rvmrc
19
+ repositories/*
20
+ !.gitkeep
21
+ __tests
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - ruby-head
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Laravel
2
2
 
3
3
  A wrapper around Laravel framework for PHP.
4
+ Currently, is only capable of downloading Laravel source from
5
+ a local directory, some git based (online/offline) repository
6
+ or from the official source on Github.
4
7
  Still in development.
5
8
 
9
+ [![Code
10
+ Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/nikhgupta/laravel)
11
+
6
12
  ## Installation
7
13
 
8
14
  Add this line to your application's Gemfile:
@@ -19,7 +25,43 @@ Or install it yourself as:
19
25
 
20
26
  ## Usage
21
27
 
22
- TODO: Write usage instructions here
28
+ ### Create a new Laravel application
29
+
30
+ Laravel gem has a caching mechanism in-built, which allows to keep a local
31
+ copy when you use the remote repositories for the first time. After this,
32
+ whenever you use the remote repository again, it will only update the local
33
+ repository (as opposed to a fresh git clone, which is considerably slow for
34
+ certain connections). This will, further, allow you to install Laravel
35
+ applications even when you are not connected to the Internet.
36
+
37
+ Since, you can specify which git repository to use to fetch the Laravel
38
+ source, you can create new Laravel application based on your own or someone
39
+ else's fork of Laravel, if required. And, yes! These repositories will be
40
+ cached!
41
+
42
+ # with default settings (fetches source from http://github.com/laravel/laravel.git)
43
+ laravel new my_app
44
+
45
+ # force a clean install on existing directory
46
+ laravel new my_app --force
47
+
48
+ # using an existing (already downloaded) source
49
+ laravel new my_app --local=/usr/src/laravel
50
+
51
+ # using a remote repository
52
+ laravel new my_app --remote="http://github.com/user/my_laravel_fork"
53
+
54
+ ### Help
55
+
56
+ laravel help
57
+
58
+ ## Coming Soon..
59
+ # create and customize a new Laravel application
60
+ laravel new my_app --index='' # set application index to blank
61
+ laravel new my_app --[no-]key # generate a new key
62
+ laravel new my_app --database=db_my_app # create a database, defaults to app name
63
+ laravel new my_app --[no-]generator # download the Laravel Generator by Jeffrey Way
64
+ laravel new my_app --bundles=sentry,bob # install the provided bundles
23
65
 
24
66
  ## Contributing
25
67
 
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/bin/laravel ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require "laravel"
12
+ require "thor"
13
+
14
+ module Laravel
15
+ class CLI < Thor
16
+
17
+ # display version/information about this gem
18
+ desc "info", "displays usage information about this gem."
19
+ method_options %w( version -v) => :boolean
20
+ def info
21
+ if options[:version]
22
+ puts "Laravel v#{Laravel::VERSION}"
23
+ else
24
+ puts Laravel::INFO
25
+ end
26
+ # puts "Made possible by efforts of Laravel Community"
27
+ end
28
+
29
+ # create a new laravel application
30
+ desc "new [MY_APP]", "install a new Laravel application"
31
+ method_option :local, :type => :string, :aliases => "-l", :banner => "DIRECTORY",
32
+ :desc => "use laravel source from a local directory"
33
+ method_option :remote, :type => :string, :aliases => "-r", :banner => "GIT_REPO",
34
+ :desc => "use this git repository instead (useful when working with forks, e.g.)"
35
+ method_option :force, :type => :boolean, :aliases => "-f",
36
+ :desc => "force overwrite"
37
+ def new(app_name)
38
+ result = Laravel::Download::source app_name, options
39
+ if result
40
+ say_status "ERROR!!", result, :red
41
+ else
42
+ say_status "Success", "Application Downloaded Successfully!"
43
+ end
44
+ end
45
+
46
+ # choose a default task to run
47
+ default_task :info
48
+
49
+ end
50
+ end
51
+
52
+ Laravel::CLI.start
data/laravel.gemspec CHANGED
@@ -17,5 +17,10 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- # gem.add_development_dependency 'rspec'
20
+ gem.add_dependency 'thor'
21
+
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'guard-rspec'
25
+ gem.add_development_dependency 'rb-fsevent'
21
26
  end
@@ -0,0 +1,81 @@
1
+ module Laravel
2
+ class Download
3
+ # This method downloads the Laravel source files.
4
+ #
5
+ # When downloading from remote repositories, it checks to see if we have
6
+ # previously used that repository (can be the official Laravel source or
7
+ # forked one). If so, it updates the local copy of that repository and
8
+ # installs from it. Otherwise, it creates a local copy of the repository
9
+ # so that future installs from that repository are instant.
10
+ #
11
+ # * *Args* :
12
+ # - +path+ -> path to the destination
13
+ # * *Returns* :
14
+ # - string containing error message, if any or is otherwise nil
15
+ #
16
+ def self.source(path, options)
17
+
18
+ # make sure that the path does not already exists (no overwrites!)
19
+ if File.exists?(path) and not options[:force]
20
+ return "directory already exists!"
21
+ end
22
+
23
+ # delete the existing files, if we are forced for this
24
+ FileUtils.rm_rf path if options[:force]
25
+
26
+ # create the requisite directory structure
27
+ FileUtils.mkdir_p File.dirname(path)
28
+
29
+ # download/update local repository as required
30
+ local_repo_for_remote_path = options[:local] || Laravel::Download::local_repository(options)
31
+
32
+ # copy the Laravel source to the required path
33
+ FileUtils.cp_r local_repo_for_remote_path, path
34
+
35
+ # remove the downloaded source if it is not a valid laravel source
36
+ unless Laravel::has_laravel? path
37
+ FileUtils.rm_rf "#{path}"
38
+ FileUtils.rm_rf "#{local_repo_for_remote_path}"
39
+ return "laravel source is corrupted!"
40
+ end
41
+
42
+ end
43
+
44
+ # Create or update local repository whenever a remote source is specified.
45
+ #
46
+ # * *Args* :
47
+ # - +options+ -> arguments passed from other tasks, if any.
48
+ # * *Returns* :
49
+ # - boolean depending on whether a download/update was done or not
50
+ #
51
+ def self.local_repository(options = {})
52
+ # do not attempt download/update if user specifically wants to stay offline
53
+ return if options.has_key?(:local)
54
+
55
+ # prefer remote path, if specifically supplied by user
56
+ # otherwise, default to the official repository
57
+ remote_repo = options[:remote] || Laravel::OfficialRepository
58
+ local_path_for_remote_repo = Laravel::crypted_path remote_repo
59
+
60
+ # get the path to the git binary
61
+ git = `which git`.strip
62
+
63
+ # string which will suppress the output of commands in quiet mode
64
+ quiet = options[:quiet] ? "&>/dev/null" : "1>/dev/null"
65
+
66
+ # update or download the remote repository
67
+ FileUtils.mkdir_p local_path_for_remote_repo
68
+ Dir.chdir local_path_for_remote_repo do
69
+ if Laravel::local_repository_exists?(remote_repo)
70
+ puts "Updating repository in local cache.." unless options[:quiet]
71
+ puts `#{git} pull #{quiet}`
72
+ else
73
+ puts "Downloading repository to local cache.." unless options[:quiet]
74
+ puts `#{git} clone #{remote_repo} . #{quiet}`
75
+ end
76
+ end
77
+
78
+ local_path_for_remote_repo
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,36 @@
1
+ require 'digest/md5'
2
+
3
+ module Laravel
4
+ LocalRepositories = File.expand_path(File.join(File.dirname(__FILE__), %w[ .. .. repositories ]))
5
+ OfficialRepository = "http://github.com/laravel/laravel.git"
6
+
7
+ # check if the given folder is a laravel source
8
+ # we check this by looking for presence of 'artisan', 'laravel/', etc.
9
+ def self.has_laravel?(directory)
10
+ return false unless File.exists? File.join( directory, "artisan" )
11
+ return false unless File.directory? File.join( directory, "laravel" )
12
+ true
13
+ end
14
+
15
+ # check if this is the first installation from this gem
16
+
17
+ # check if local repository exists for a given remote git source
18
+ def self.local_repository_exists?(source)
19
+ local_repository_path = Laravel::crypted_path(source)
20
+ if Laravel::has_laravel? local_repository_path
21
+ local_repository_path
22
+ else
23
+ nil
24
+ end
25
+ end
26
+
27
+ # return the crypted folder name for a given remote repository
28
+ def self.crypted_name(source)
29
+ (Digest::MD5.new << source).to_s
30
+ end
31
+
32
+ # return the crypted folder path for a given remote repository
33
+ def self.crypted_path(source)
34
+ File.join(Laravel::LocalRepositories, Laravel::crypted_name(source))
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ module Laravel
2
+ INFO = '''
3
+ Create a new Laravel application
4
+
5
+ # with default settings
6
+ # fetches source from http://github.com/laravel/laravel.git
7
+ laravel new my_app
8
+
9
+ # force a clean install on existing directory
10
+ laravel new my_app --force
11
+
12
+ # using an existing (already downloaded) source
13
+ laravel new my_app --local=/usr/src/laravel
14
+
15
+ # using a remote repository
16
+ laravel new my_app --remote="http://github.com/user/my_laravel_fork"
17
+ '''
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Laravel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/laravel.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require "laravel/version"
2
-
3
- module Laravel
4
- class Hello
5
- puts "Hello World!\n I am still prepping up myself.. Stay tuned!"
6
- end
7
- end
2
+ require "laravel/info"
3
+ require "laravel/helpers"
4
+ require "laravel/download"
File without changes
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Laravel::Download do
4
+
5
+ before(:each) { Laravel::Tests::cleanup }
6
+ after(:each) { Laravel::Tests::cleanup }
7
+
8
+ it "should download source from a manually specified laravel repository" do
9
+ # preparations
10
+ options = { :remote => "https://github.com/laravel/pastes.git" }
11
+ Laravel::Tests::cleanup options[:remote]
12
+
13
+ # actions
14
+ print " downloading git repository.. this may take a while.."
15
+ app_path = Laravel::Tests::app_downloads_nicely? options
16
+
17
+ # expectations
18
+ app_path.should_not be_nil
19
+ Laravel::local_repository_exists?(options[:remote])
20
+ Laravel::Tests::download_was_performed?(app_path)
21
+ end
22
+
23
+ it "should not download source from a non-laravel app" do
24
+ # preparations
25
+ options = { :remote => "http://github.com/nikhgupta/snipmate-snippets.git" }
26
+
27
+ # actions
28
+ print " downloading git repository.. this may take a while.."
29
+ app_path = Laravel::Tests::app_downloads_nicely? options
30
+
31
+ # expectations
32
+ app_path.should be_nil
33
+ !Laravel::local_repository_exists?(options[:remote])
34
+ !Laravel::Tests::download_was_performed?(app_path)
35
+ end
36
+
37
+ it "should download source from the official repository" do
38
+ # preparations
39
+ Laravel::Tests::cleanup Laravel::OfficialRepository
40
+
41
+ # actions
42
+ print " downloading git repository.. this may take a while.."
43
+ app_path = Laravel::Tests::app_downloads_nicely?
44
+
45
+ # expectations
46
+ app_path.should_not be_nil
47
+ Laravel::local_repository_exists?(Laravel::OfficialRepository)
48
+ Laravel::Tests::download_was_performed?(app_path)
49
+ end
50
+
51
+ it "should copy source from local repository cache" do
52
+ # preparations
53
+ # should only be run with the previous test
54
+ # act as cached repo
55
+ options = { :remote => Laravel::crypted_path(Laravel::OfficialRepository) }
56
+
57
+ # actions
58
+ app_path = Laravel::Tests::app_downloads_nicely?
59
+
60
+ # expectations
61
+ app_path.should_not be_nil
62
+ Laravel::Tests::download_was_performed?(app_path)
63
+ end
64
+
65
+ it "should copy source from a manually specified directory" do
66
+ # preparations
67
+ # acts as local directory
68
+ options = { :local => Laravel::crypted_path(Laravel::OfficialRepository) }
69
+
70
+ # actions
71
+ app_path = Laravel::Tests::app_downloads_nicely? options
72
+
73
+ # expectations
74
+ app_path.should_not be_nil
75
+ Laravel::Tests::download_was_performed?(app_path)
76
+ end
77
+
78
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Laravel do
4
+ it "should have a version" do
5
+ Laravel::VERSION.should_not be_nil
6
+ end
7
+
8
+ context "when creating a new application" do
9
+
10
+ before(:each) { Laravel::Tests::cleanup }
11
+ after(:each) { Laravel::Tests::cleanup }
12
+
13
+ it "should run with default options" do
14
+ # actions
15
+ print ' downloading git repository.. this may take a while..'
16
+ app_path = Laravel::Tests::app_downloads_nicely?
17
+
18
+ # expectations
19
+ app_path.should_not be_nil
20
+ Laravel::Tests::app_was_created? app_path
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,45 @@
1
+ require 'laravel'
2
+
3
+ module Laravel
4
+ class Tests
5
+ TestAppDirectory = File.join( File.dirname(__FILE__), %w[ .. __tests ] )
6
+
7
+ # get path to the test application
8
+ def self.app_path(app_name)
9
+ File.join(Laravel::Tests::TestAppDirectory, app_name)
10
+ end
11
+
12
+ # perform an application download using Laravel::Download
13
+ def self.app_downloads_nicely?(options = {}, app_name = "")
14
+ app_name ||= (('a'..'z').to_a+('A'..'Z').to_a).shuffle[0,32].join
15
+ options[:quiet] = true
16
+ app_path = Laravel::Tests::app_path app_name
17
+ error = Laravel::Download::source(app_path, options)
18
+ error ? nil : app_path
19
+ end
20
+
21
+ # check if the download was successful
22
+ def self.download_was_performed?(app_path)
23
+ app_path && File.directory?(app_path)
24
+ end
25
+
26
+ # check if the application was created?
27
+ def self.app_was_created?(app_path)
28
+ return false unless Laravel::Tests::download_was_performed?(app_path)
29
+ return false unless Laravel::has_laravel?(app_path)
30
+ true
31
+ end
32
+
33
+ # cleanup before and after our tests
34
+ def self.cleanup(repo = "")
35
+ FileUtils.rm_rf Laravel::Tests::TestAppDirectory
36
+ FileUtils.rm_rf Laravel::crypted_path(repo) if repo
37
+ end
38
+ end
39
+ end
40
+
41
+ RSpec.configure do |c|
42
+ c.fail_fast = true
43
+ c.color = true
44
+ c.formatter = :documentation
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laravel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,23 +9,114 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-17 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-fsevent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
14
94
  description: A wrapper around Laravel framework for PHP
15
95
  email:
16
96
  - me@nikhgupta.com
17
- executables: []
97
+ executables:
98
+ - laravel
18
99
  extensions: []
19
100
  extra_rdoc_files: []
20
101
  files:
21
102
  - .gitignore
103
+ - .travis.yml
22
104
  - Gemfile
105
+ - Guardfile
23
106
  - LICENSE.txt
24
107
  - README.md
25
108
  - Rakefile
109
+ - bin/laravel
26
110
  - laravel.gemspec
27
111
  - lib/laravel.rb
112
+ - lib/laravel/download.rb
113
+ - lib/laravel/helpers.rb
114
+ - lib/laravel/info.rb
28
115
  - lib/laravel/version.rb
116
+ - repositories/.gitkeep
117
+ - spec/laravel/download/download_spec.rb
118
+ - spec/laravel/laravel_spec.rb
119
+ - spec/spec_helper.rb
29
120
  homepage: https://rubygems.org/gems/laravel
30
121
  licenses: []
31
122
  post_install_message:
@@ -52,4 +143,7 @@ specification_version: 3
52
143
  summary: This gem is a wrapper around the Laravel framework for PHP. Initially, the
53
144
  gem would allow to create new laravel apps along with options to modify the default
54
145
  behavior for these new installations.
55
- test_files: []
146
+ test_files:
147
+ - spec/laravel/download/download_spec.rb
148
+ - spec/laravel/laravel_spec.rb
149
+ - spec/spec_helper.rb