motion-require 0.0.1
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.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/lib/motion-require/version.rb +5 -0
- data/lib/motion-require.rb +82 -0
- data/motion/ext.rb +6 -0
- data/motion-require.gemspec +15 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Clay Allsopp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# motion-require
|
2
|
+
|
3
|
+
Miss `require`? Well, this is a step in that direction:
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
# in a RubyMotion file
|
7
|
+
motion_require "base_view_controller"
|
8
|
+
motion_require "../util/controller_helper"
|
9
|
+
|
10
|
+
class MyController < BaseViewController
|
11
|
+
include ControllerHelper
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# in your Rakefile
|
17
|
+
require 'motion/project'
|
18
|
+
|
19
|
+
require 'motion-require'
|
20
|
+
Motion::Require.all(Dir.glob("app/**/*.rb")
|
21
|
+
|
22
|
+
Motion::Project::App.setup do |app|
|
23
|
+
# ...
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+

|
28
|
+
|
29
|
+
It's used in:
|
30
|
+
- [Formotion](https://github.com/clayallsopp/formotion)
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
`gem install motion-require`
|
35
|
+
|
36
|
+
Can also add to your `Gemfile` etc
|
37
|
+
|
38
|
+
## How?
|
39
|
+
|
40
|
+
motion-require uses static analysis (via [`ripper`](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ripper/rdoc/Ripper.html)) to find the files using `motion_require` and automatically add the declared dependencies to `Motion::Project::Config#dependencies`. Then the `Kernel#motion_require` method is overriden at compile-time to be a noop.
|
41
|
+
|
42
|
+
The paths attached to `motion_require` are treated like those with `require_relative`.
|
43
|
+
|
44
|
+
## Contact
|
45
|
+
|
46
|
+
Clay Allsopp ([http://clayallsopp.com](http://clayallsopp.com))
|
47
|
+
|
48
|
+
- [http://twitter.com/clayallsopp](http://twitter.com/clayallsopp)
|
49
|
+
- [clay@usepropeller.com](clay@usepropeller.com)
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
motion-require is available under the MIT license. See the LICENSE file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
module Motion
|
4
|
+
module Require
|
5
|
+
class RequireBuilder < Ripper::SexpBuilder
|
6
|
+
REQUIREMENT_TOKEN = "motion_require"
|
7
|
+
|
8
|
+
attr_accessor :requires
|
9
|
+
|
10
|
+
def requires
|
11
|
+
@requires ||= []
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_command(command, args) # scanner event
|
15
|
+
type, name, position = command
|
16
|
+
if name == REQUIREMENT_TOKEN
|
17
|
+
file = parse_args(args)
|
18
|
+
requires << file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_args(args)
|
23
|
+
value = nil
|
24
|
+
args.each do |arg|
|
25
|
+
if arg.is_a?(Array)
|
26
|
+
type = arg.first
|
27
|
+
if type == :@tstring_content
|
28
|
+
return arg[1]
|
29
|
+
end
|
30
|
+
|
31
|
+
value = parse_args(arg)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module_function
|
39
|
+
def dependencies_for(files)
|
40
|
+
dependencies = {}
|
41
|
+
files.each do |file_path|
|
42
|
+
requires = requires_in(file_path)
|
43
|
+
if !requires.empty?
|
44
|
+
dependencies[file_path] = requires.map { |required|
|
45
|
+
if required[-3..-1] != ".rb"
|
46
|
+
required += ".rb"
|
47
|
+
end
|
48
|
+
absolute_path(file_path, required)
|
49
|
+
}
|
50
|
+
dependencies[file_path].unshift ext_file
|
51
|
+
end
|
52
|
+
end
|
53
|
+
dependencies
|
54
|
+
end
|
55
|
+
|
56
|
+
def requires_in(file)
|
57
|
+
parser = Motion::Require::RequireBuilder.new(File.read(file))
|
58
|
+
parser.parse
|
59
|
+
parser.requires
|
60
|
+
end
|
61
|
+
|
62
|
+
def absolute_path(source, required)
|
63
|
+
File.expand_path(File.join(File.dirname(source), required.to_str))
|
64
|
+
end
|
65
|
+
|
66
|
+
def all(files)
|
67
|
+
Motion::Project::App.setup do |app|
|
68
|
+
app.files << ext_file
|
69
|
+
files.each do |file|
|
70
|
+
app.files << file
|
71
|
+
end
|
72
|
+
|
73
|
+
dependencies = dependencies_for(files)
|
74
|
+
app.files_dependencies dependencies
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def ext_file
|
79
|
+
File.expand_path(File.join(File.dirname(__FILE__), "../motion/ext.rb"))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/motion/ext.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/motion-require/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "motion-require"
|
6
|
+
s.version = Motion::Require::VERSION
|
7
|
+
s.authors = ["Clay Allsopp"]
|
8
|
+
s.email = ["clay@usepropeller.com"]
|
9
|
+
s.homepage = "https://github.com/clayallsopp/motion-require"
|
10
|
+
s.summary = "Dependency management for RubyMotion, using a pseudo `require`"
|
11
|
+
s.description = "Dependency management for RubyMotion, using a pseudo `require`"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-require
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Clay Allsopp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Dependency management for RubyMotion, using a pseudo `require`
|
15
|
+
email:
|
16
|
+
- clay@usepropeller.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/motion-require.rb
|
27
|
+
- lib/motion-require/version.rb
|
28
|
+
- motion-require.gemspec
|
29
|
+
- motion/ext.rb
|
30
|
+
homepage: https://github.com/clayallsopp/motion-require
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.23
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Dependency management for RubyMotion, using a pseudo `require`
|
54
|
+
test_files: []
|