javascripto 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 ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in javascripto.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Javascripto
2
+ ============
3
+ Client-side Javascript Application Framework
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "javascripto/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "javascripto"
7
+ s.version = Javascripto::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Blake Taylor"]
10
+ s.email = ["btaylor@agoragames.com"]
11
+ s.homepage = "http://javascripto.com"
12
+ s.summary = %q{Client-side Javascript Application Framework}
13
+ # s.description = %q{TODO: Write a gem description}
14
+
15
+ s.rubyforge_project = "javascripto"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+ require 'javascripto/file'
3
+ require 'javascripto/package'
4
+ require 'javascripto/required_packages'
5
+
6
+ # Client-side Javascript Application Framework
7
+ module Javascripto
8
+ end
@@ -0,0 +1,123 @@
1
+ require 'javascripto/package'
2
+
3
+ module Javascripto
4
+ class File < Package
5
+
6
+ # Define Constants
7
+ JS = '.js' #extensions
8
+
9
+ # File Repository
10
+ @@files = {}
11
+ @@path_lookup_cache = {}
12
+
13
+ def self.js_root=(root)
14
+ @@js_root = root
15
+ @@load_path = ['lib', *Dir.glob(::File.join(@@js_root, "vendor/*")).map{|entry| "vendor/#{::File.basename(entry)}" } ]
16
+ end
17
+
18
+ attr_accessor :path, :package
19
+
20
+ def initialize(path)
21
+ @path = path
22
+ end
23
+
24
+ def file_dependencies
25
+ if @file_dependencies
26
+ return @file_dependencies
27
+ end
28
+
29
+ # Only scan up to 15 lines.
30
+ lines = []
31
+ ::File.open(@@js_root.join(@path + JS), "r") do |file|
32
+ 15.times do
33
+ if line = file.gets
34
+ lines << line
35
+ else
36
+ break
37
+ end
38
+ end
39
+ end
40
+
41
+ # Indentify required files
42
+ required_files = lines.map do |line|
43
+ match = /\s*^\/\/\s*require(.*)/.match(line)
44
+ if match
45
+ # Remove whitespace and break on comma for multiple files
46
+ match.captures[0].strip.split(/\s*,\s*/)
47
+ end
48
+ end.flatten.compact.uniq
49
+
50
+ @file_dependencies = required_files.map{ |required_file| File.get_file(required_file) }
51
+ end
52
+
53
+ # Return the file object instance.
54
+ def self.get_file(file_path)
55
+
56
+ # Expand the file path.
57
+ file_path = expand_path(file_path)
58
+
59
+ # Look for the file object.
60
+ if @@files[file_path]
61
+ return @@files[file_path]
62
+ end
63
+
64
+ # Otherwise create a new one.
65
+ @@files[file_path] = File.new(file_path)
66
+ end
67
+
68
+ # Override Package Methods
69
+ def package_files
70
+ [self]
71
+ end
72
+
73
+ def package_name
74
+ @path
75
+ end
76
+
77
+ def package_dependencies
78
+ unless @package_dependencies
79
+ @package_dependencies = []
80
+
81
+ # For each file dependency
82
+ file_dependencies.each do |dependency|
83
+ # It it's not already in a package...
84
+ unless dependency.package
85
+ # ...Make it it's own package.
86
+ dependency.package = dependency
87
+ end
88
+ # Add files_dependency package as a package dependency.
89
+ @package_dependencies << dependency.package
90
+ end
91
+ # Remove duplicates.
92
+ @package_dependencies.uniq!
93
+ end
94
+ @package_dependencies
95
+ end
96
+
97
+ private
98
+
99
+ # Search load_path for file and return public path.
100
+ def self.expand_path(file)
101
+ if @@path_lookup_cache[file]
102
+ return @@path_lookup_cache[file]
103
+ end
104
+
105
+ # Check Root.
106
+ @@path_lookup_cache[file] = ::File.join(file) if @@js_root.join(file + JS).exist?
107
+ return @@path_lookup_cache[file] if @@path_lookup_cache[file]
108
+
109
+ # Search rest of load path.
110
+ load_path.each do |path|
111
+ @@path_lookup_cache[file] = ::File.join(path, file) if @@js_root.join(path, file + JS).exist?
112
+ return @@path_lookup_cache[file] if @@path_lookup_cache[file]
113
+ end
114
+
115
+ raise ArgumentError.new "Could not find #{file + JS} in the load_path => #{load_path}."
116
+ end
117
+
118
+ def self.load_path
119
+ @@load_path
120
+ end
121
+
122
+ end
123
+ end
@@ -0,0 +1,29 @@
1
+ module Javascripto
2
+ class Package
3
+
4
+ attr_reader :package_name, :package_files, :package_dependencies
5
+
6
+ def initialize(package_name, files)
7
+ @package_name = package_name
8
+ @package_files, @package_dependencies = [], []
9
+ files.each do |file|
10
+ add_file_and_dependencies(file)
11
+ end
12
+ end
13
+
14
+ def add_file_and_dependencies(file, stack = [])
15
+ # If the file is already contained in another package
16
+ if file.package
17
+ # ..add the other package as a dependency...
18
+ @package_dependencies << file.package unless self == file.package
19
+ else
20
+ # ...otherwise, add this file and all of its unpackaged dependecies to this package.
21
+ file.file_dependencies.each do |dependency|
22
+ add_file_and_dependencies(dependency, stack << file)
23
+ end
24
+ @package_files << file
25
+ file.package = self
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ require 'enumerator'
2
+ require 'javascripto/file'
3
+
4
+ module Javascripto
5
+ class RequiredPackages
6
+ include Enumerable
7
+
8
+ def initialize
9
+ @required_packages = []
10
+ end
11
+
12
+ def each
13
+ @required_packages.each { |package| yield package }
14
+ end
15
+
16
+ def add_files(*file_paths)
17
+ # Make sure config.js is included as first dependency, but only when somthing else has been added.
18
+ if @required_packages.empty?
19
+ file_paths.unshift 'config'
20
+ end
21
+
22
+ file_paths.each do |file_path|
23
+ # Resolve the file object from the path.
24
+ file = File.get_file(file_path)
25
+ # If the file is not a part of a package...
26
+ unless file.package
27
+ # ...set itself as the package.
28
+ file.package = file
29
+ end
30
+ require_package file.package
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def require_package(package, stack = [])
37
+ # Skip if the package is already included.
38
+ unless @required_packages.include? package
39
+ # If not, Resolve dependcies and interveve?
40
+ package.package_dependencies.each do |dependency|
41
+ unless stack.length > 5
42
+ require_package(dependency, stack << package)
43
+ stack.pop
44
+ else
45
+ raise RuntimeError.new("Failed to resolve package dependecies before reaching recurison limit of 5. Stack: #{stack.map{ |item| item.package_name }} ")
46
+ end
47
+ end
48
+ @required_packages << package
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Javascripto
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: javascripto
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Blake Taylor
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-17 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email:
23
+ - btaylor@agoragames.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - javascripto.gemspec
36
+ - lib/javascripto.rb
37
+ - lib/javascripto/file.rb
38
+ - lib/javascripto/package.rb
39
+ - lib/javascripto/required_packages.rb
40
+ - lib/javascripto/version.rb
41
+ has_rdoc: true
42
+ homepage: http://javascripto.com
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project: javascripto
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Client-side Javascript Application Framework
73
+ test_files: []
74
+