laravel 0.2.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ module Laravel
2
+ # This class handles the configuration aspects of a Laravel based
3
+ # application. This allows us to read and update settings in
4
+ # ./application/config/application.php Furthermore, it allows us to read and
5
+ # update various options, at one go.
6
+ class Configuration < App
7
+
8
+ # This method creates dynamic read/update methods exposed by this class.
9
+ # For this to work, the exposed functions have a definite naming
10
+ # convention: {action}_{setting}, where {action} can be either 'read' or
11
+ # 'update', and {setting} can be one of the settings found in the
12
+ # configuration file.
13
+ #
14
+ # For example: calling: update_index("home.php") will update the 'index'
15
+ # setting to use 'home.php' also, calling: update_key() will update the
16
+ # 'key' to a 32-char long string.
17
+ #
18
+ # The second example above automatically generates a 32-char string by
19
+ # calling 'do_update_key' method implicitely, which returns this string.
20
+ #
21
+ # The 'do_{method}' methods must be defined in this class, which return the
22
+ # manipulated input from callee.
23
+ #
24
+ def method_missing(name, *args)
25
+ # capture the input from callee
26
+ value = args[0]
27
+
28
+ # understand what the callee is requesting..
29
+ dissect = name.to_s.split "_"
30
+ action = dissect[0]
31
+ setting = dissect[1]
32
+
33
+ # lets manipulate the input value if a 'do_{method}' exists
34
+ new_value = method("do_#{name}").call(value) if Configuration.method_defined?("do_#{name}".to_sym)
35
+ # otherwise, use the passed value without any manipulations
36
+ new_value = value if new_value.nil? or new_value.strip.empty?
37
+
38
+ # handle the {action} part of the method
39
+ # performs a read/update on the Configuration setting.
40
+ response = case action
41
+ when "read" then __read_config(setting)
42
+ when "update" then __update_config(setting, new_value)
43
+ else show_error "Do not know how to configure this setting!"
44
+ end
45
+
46
+ # let the user know when we set the value to an empty string
47
+ new_value = "__empty_string__" if new_value.nil? or new_value.strip.empty?
48
+
49
+ # Let the user know that we have performed an action
50
+ if response and action != "read"
51
+ say_success "#{action.capitalize}d configuration: #{setting} => #{new_value}"
52
+ else
53
+ say_failed "Could not #{action} configuration: #{setting.capitalize}!"
54
+ end
55
+ end
56
+
57
+ # update the configuration settings by looking at the options
58
+ # that the user has provided when running the 'new' task.
59
+ #
60
+ def update_from_options
61
+ # don't do anything, unless options were provided
62
+ return unless @options
63
+
64
+ # update permissions on storage/ directory (this is the default)
65
+ update_permissions_on_storage if @options[:perms]
66
+ # update Application Index, if provided
67
+ update_index @options[:index] unless @options[:index].nil?
68
+ # generate a new key, if asked for.
69
+ update_key if @options[:key]
70
+ end
71
+
72
+ # lets generate the random string required by the 'update_key' method
73
+ #
74
+ # ==== Parameters
75
+ # +value+:: optional string, that if provided will be used as the new key
76
+ # instead of generating a random one.
77
+ #
78
+ # ==== Returns
79
+ # String:: the new key for the application
80
+ def do_update_key(value = nil)
81
+ make_md5
82
+ end
83
+
84
+ private
85
+
86
+ # handle the config update routine.
87
+ # this method first checks to see if the current app is a Laravel
88
+ # based application, and then performs the update for this setting.
89
+ # Finally, it checks whether the update was successful and returns it.
90
+ #
91
+ # ==== Parameters
92
+ # +key+:: the configuration setting which will be updated
93
+ # +new_value:: the new value for the configuration defined by +key+
94
+ #
95
+ # ==== Returns
96
+ # Boolean:: true if the update was successful.
97
+ #
98
+ def __update_config(key, new_value)
99
+ # default to current working directory if path is not specified
100
+ conf = config_file
101
+
102
+ # try to change configuration only if this is a Laravel application
103
+ # otherwise, raise an error
104
+ if has_laravel?
105
+
106
+ # make the required substitution in the configuration file
107
+ text = File.read conf
108
+ text = text.gsub(/'#{key}' => '.*'/, "'#{key}' => '#{new_value}'")
109
+ File.open(conf, "w") {|file| file.puts text}
110
+
111
+ # check to ensure we were able to update configuration
112
+ File.readlines(conf).grep(/'#{key}' => '#{new_value}'/).any?
113
+ else
114
+ show_error "Is this a valid Laravel application?"
115
+ end
116
+ end
117
+
118
+ end
119
+ end
@@ -0,0 +1,61 @@
1
+ module Laravel
2
+ # This class handles the installation of certain tasks or some bundles, e.g.
3
+ # bob, sentry, etc. Since, these installation do not follow a definite
4
+ # pattern, we will need to define method that handles a particular
5
+ # installation.
6
+ class Installer < App
7
+
8
+ # This method acts as a gateway for the installation methods exposed by
9
+ # this class. The exposed methods follow a definite naming convention:
10
+ # {type}_{resource}, where {type} can either be 'task' or 'bundle', and
11
+ # {resource} is the name of the thing we are trying to install.
12
+ #
13
+ # For example: calling: task_generator() will install a task in the
14
+ # application/tasks/ folder, where 'do_task_generator' method defines how
15
+ # the particular install wil really be handled. Please, have a look at the
16
+ # source code of the above example for more information.
17
+ #
18
+ # The 'do_{method}' methods must be defined in this class, which actually
19
+ # handle the installation routine for us. These methods must have 'boolean'
20
+ # as their return value.
21
+ #
22
+ def method_missing(name, *args)
23
+ # know what we are doing
24
+ dissect = name.to_s.split "_"
25
+ type = dissect[0]
26
+ source = dissect[1]
27
+
28
+ # we MUST have a 'do_{method}' defined!!
29
+ if Installer.method_defined?("do_#{name}".to_sym)
30
+
31
+ if method("do_#{name}").call
32
+ say_success "Installed #{type}: #{source.capitalize}"
33
+ else
34
+ say_failed "Could not install #{type}: #{source.capitalize}"
35
+ end
36
+ else
37
+ say_failed "Don't know how to install #{source.capitalize}!"
38
+ end
39
+ end
40
+
41
+ # install the particular tasks or bundles by looking the options
42
+ # that the user has provided when running the 'new' task.
43
+ #
44
+ def from_options
45
+ return unless @options
46
+
47
+ # read and perform installs from options passed through the command line.
48
+ task_generator if @options[:generator]
49
+ end
50
+
51
+ # Install the Laravel Generator by Jeffrey Way. This creates a file named
52
+ # 'generate.php' in the application/tasks/ folder, which can be invoked as:
53
+ # `php artisan generate` using artisan.
54
+ #
55
+ def do_task_generator
56
+ url = "https://raw.github.com/JeffreyWay/Laravel-Generator/master/generate.php"
57
+ # download the Laravel Generator using curl as 'generate.php'
58
+ download_resource(tasks_file("generate.php"), url, "curl")
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Laravel
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.2"
3
3
  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.2.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2012-12-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -73,6 +73,9 @@ files:
73
73
  - LICENSE.txt
74
74
  - README.md
75
75
  - Rakefile
76
+ - bin/commands/config.rb
77
+ - bin/commands/install.rb
78
+ - bin/commands/new.rb
76
79
  - bin/laravel
77
80
  - features/S_1_new.feature
78
81
  - features/S_2_generate_key.feature
@@ -83,12 +86,11 @@ files:
83
86
  - features/support/laravel_helpers.rb
84
87
  - laravel.gemspec
85
88
  - lib/laravel.rb
86
- - lib/laravel/create.rb
87
- - lib/laravel/helpers.rb
88
- - lib/laravel/info.rb
89
- - lib/laravel/manage.rb
89
+ - lib/laravel/app.rb
90
+ - lib/laravel/app_support.rb
91
+ - lib/laravel/configuration.rb
92
+ - lib/laravel/installer.rb
90
93
  - lib/laravel/version.rb
91
- - repositories/.gitkeep
92
94
  homepage: https://github.com/nikhgupta/laravel
93
95
  licenses: []
94
96
  post_install_message:
@@ -103,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
105
  version: '0'
104
106
  segments:
105
107
  - 0
106
- hash: 3710655952266878729
108
+ hash: 3739253093214665675
107
109
  required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  none: false
109
111
  requirements:
@@ -112,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  version: '0'
113
115
  segments:
114
116
  - 0
115
- hash: 3710655952266878729
117
+ hash: 3739253093214665675
116
118
  requirements: []
117
119
  rubyforge_project:
118
120
  rubygems_version: 1.8.24
@@ -1,121 +0,0 @@
1
- module Laravel
2
- class Create
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
- # get some information about this path
18
- path = File.expand_path(path)
19
- is_current_dir = (path == File.expand_path('.'))
20
- is_not_empty = (Dir.entries(path).size > 2) if File.exists?(path)
21
-
22
- # make sure that the path does not already exists (no overwrites!)
23
- if ((File.exists?(path) and not is_current_dir) or (is_current_dir and is_not_empty)) and not options[:force]
24
- Laravel::say_error "directory already exists or is not empty!"
25
- end
26
-
27
- # delete the existing files, if we are forced for this
28
- if options[:force]
29
- Laravel::say_info "Creating application forcefully!"
30
- is_current_dir ? FileUtils.rm_rf("#{path}/.", :secure => true) : FileUtils.rm_rf(path)
31
- end
32
-
33
- # create the requisite directory structure
34
- FileUtils.mkdir_p File.dirname(path) unless is_current_dir
35
-
36
- # download/update local repository as required
37
- local_repo_for_remote_path = options[:local] || self.local_repository(options)
38
-
39
- # copy the Laravel source to the required path
40
- if is_current_dir
41
- FileUtils.cp_r "#{local_repo_for_remote_path}/.", path
42
- else
43
- FileUtils.cp_r local_repo_for_remote_path, path
44
- end
45
-
46
- # make necessary changes for the new app, if we were successful in download
47
- # otherwise, remove the downloaded source
48
- if Laravel::has_laravel? path
49
- Laravel::say_success "Cloned Laravel repository."
50
- if options[:perms]
51
- storage_directory = File.join(path, "storage")
52
- response = system("chmod -R o+w #{storage_directory}")
53
- if response
54
- Laravel::say_success "Updated permissions on storage/ directory."
55
- else
56
- Laravel::say_failed "Could not update permissiosn on storage/ directory."
57
- end
58
- end
59
- Laravel::Manage::update_index options[:index], path if options.has_key?("index")
60
- Laravel::Manage::generate_key path if options.has_key?("key")
61
- Laravel::Manage::get_generator path if options.has_key?("generator")
62
- Laravel::say_success "Hurray! Your Laravel application has been created!"
63
- else
64
- Laravel::say_failed "Downloaded source is not Laravel framework or a possible fork."
65
- Laravel::say_info "Cleaning up.."
66
- FileUtils.rm_rf "#{path}" unless is_current_dir
67
- # delete_corrupted = Laravel::yes? "Should I delete the specified repository from local cache? (default: yes)"
68
- # if delete_corrupted
69
- # Laravel::say_info "Deleting local cache for this source!"
70
- # FileUtils.rm_rf "#{local_repo_for_remote_path}"
71
- # else
72
- # Laravel::say_info "Local cache for this source was not deleted!"
73
- # end
74
- FileUtils.rm_rf "#{local_repo_for_remote_path}"
75
- Laravel::say_error "Specified Laravel source is corrupt!"
76
- end
77
- end
78
-
79
- # Create or update local repository whenever a remote source is specified.
80
- #
81
- # * *Args* :
82
- # - +options+ -> arguments passed from other tasks, if any.
83
- # * *Returns* :
84
- # - boolean depending on whether a download/update was done or not
85
- #
86
- def self.local_repository(options = {})
87
- # do not attempt download/update if user specifically wants to stay offline
88
- return if options.has_key?("local")
89
-
90
- # prefer remote path, if specifically supplied by user
91
- # otherwise, default to the official repository
92
- remote_repo = options[:remote] || Laravel::OfficialRepository
93
- local_path_for_remote_repo = Laravel::crypted_path remote_repo
94
-
95
- # get the path to the git binary
96
- git = `which git`.strip
97
-
98
- # string which will suppress the output of commands in quiet mode
99
- # quiet = options[:quiet] ? "&>/dev/null" : "1>/dev/null"
100
- quiet = "&>/dev/null"
101
-
102
- # update or download the remote repository
103
- FileUtils.mkdir_p local_path_for_remote_repo
104
- # say_info "Created requisite directory structure."
105
- Dir.chdir local_path_for_remote_repo do
106
- # do an update if cache exists, otherwise download it
107
- # do this every time before creating new app so that we are always up-to-date
108
- if Laravel::local_repository_exists?(remote_repo)
109
- Laravel::say_info "Repository exists in local cache.."
110
- Laravel::say_info "Updating repository in local cache.."
111
- print `#{git} pull #{quiet}`
112
- else
113
- Laravel::say_info "Downloading repository to local cache.."
114
- print `#{git} clone #{remote_repo} . #{quiet}`
115
- end
116
- end
117
-
118
- local_path_for_remote_repo
119
- end
120
- end
121
- end
@@ -1,59 +0,0 @@
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 local repository exists for a given remote git source
16
- def self.local_repository_exists?(source)
17
- local_repository_path = Laravel::crypted_path(source)
18
- Laravel::has_laravel?(local_repository_path) ? local_repository_path : nil
19
- end
20
-
21
- # return the crypted folder name for a given remote repository
22
- def self.crypted_name(source)
23
- (Digest::MD5.new << source).to_s
24
- end
25
-
26
- # return the crypted folder path for a given remote repository
27
- def self.crypted_path(source)
28
- File.join(Laravel::LocalRepositories, Laravel::crypted_name(source))
29
- end
30
-
31
- # ask user for confirmation
32
- def self.yes?(message, color=nil)
33
- shell = Thor::Shell::Color.new
34
- shell.yes?(message, color)
35
- end
36
-
37
- # say something to the user.
38
- def self.say(status, message = "", log_status = true)
39
- shell = Thor::Shell::Color.new
40
- shell.say_status(status, message, log_status)
41
- end
42
-
43
- def self.say_info(message)
44
- self.say "Information", message, :cyan
45
- end
46
-
47
- def self.say_success(message)
48
- self.say "Success", message, :green
49
- end
50
-
51
- def self.say_failed(message)
52
- self.say "Failed!!", message, :yellow
53
- end
54
-
55
- def self.say_error(message)
56
- self.say "!!ERROR!!", message, :red
57
- exit
58
- end
59
- end
@@ -1,45 +0,0 @@
1
- module Laravel
2
- INFO = '''
3
- Run `laravel help` for more details
4
-
5
- Create a new Laravel application
6
- ================================
7
- laravel new my_app
8
- # use default settings
9
- # fetches source from http://github.com/laravel/laravel.git
10
- laravel new my_app --force
11
- # force a clean install on existing directory
12
- laravel new my_app --remote="http://github.com/user/my_laravel_fork"
13
- # use an existing (already downloaded) source
14
- # use a remote repository
15
- laravel new my_app --index=home.php
16
- # use default settings and update Application Index
17
- laravel new my_app --key
18
- # use default settings and generate a new key
19
- laravel new my_app --no-perms
20
- # use default settings but do not update permissions on storage/ directory
21
- laravel new my_app --generator
22
- # use default settings and downloaded Laravel generator by Jeffrey Way
23
-
24
- Update Application Index on existing Laravel applications
25
- =========================================================
26
- laravel update_index "home.php"
27
- # in the current directory
28
- laravel update_index "" --app=./laravel
29
- # for application in the specified directory
30
-
31
- Generate a key on existing Laravel applications
32
- ===============================================
33
- laravel generate_key
34
- # in the current directory
35
- laravel generate_key --app=./laravel
36
- # for application in the specified directory
37
-
38
- Download Laraevl Generator by Jeffrey Way
39
- =========================================
40
- laravel get_generator
41
- # in the current directory
42
- laravel get_generator --app=./laravel
43
- # for application in the specified directory
44
- '''
45
- end