Skip to content

Commit

Permalink
Adding the ability to specify js libraries that need to be loaded wit…
Browse files Browse the repository at this point in the history
…h js runtime running kernel code. This change alters the structure of mainfest.yml for all three projects by adding features and kernel_libs as two distinct sections. Any files added in kernel_libs will be added to load_file.txt for all platforms and will be loaded while initializing the js runtime for kernel code.
  • Loading branch information
priyaaank committed May 18, 2013
1 parent 4b4b288 commit e19af8d
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
24 changes: 20 additions & 4 deletions lib/calatrava/app_builder.rb
Expand Up @@ -22,11 +22,27 @@ def js_file(cf)
"#{build_scripts_dir}/#{File.basename(cf, '.coffee')}.js" "#{build_scripts_dir}/#{File.basename(cf, '.coffee')}.js"
end end


def load_instructions def change_path_to_relative files, &change_file_path
build_path = Pathname.new(File.dirname(build_dir)) build_path = Pathname.new(File.dirname(build_dir))
@manifest.kernel_bootstrap.collect do |cf| files.collect do |file_to_add|
Pathname.new(js_file(cf)).relative_path_from(build_path).to_s Pathname.new(change_file_path.call(file_to_add)).relative_path_from(build_path).to_s
end.join($/) end
end

def library_files
change_path_to_relative @manifest.kernel_libraries do |js_library|
"#{build_scripts_dir}/#{File.basename(js_library)}"
end
end

def feature_files
change_path_to_relative @manifest.kernel_bootstrap do |coffee_file|
js_file(coffee_file)
end
end

def load_instructions
feature_files.concat(library_files).join($/)
end end


def haml_files def haml_files
Expand Down
8 changes: 7 additions & 1 deletion lib/calatrava/manifest.rb
Expand Up @@ -8,7 +8,13 @@ class Manifest
def initialize(path, app_dir, kernel, shell) def initialize(path, app_dir, kernel, shell)
@path, @kernel, @shell = path, kernel, shell @path, @kernel, @shell = path, kernel, shell
@src_file = "#{app_dir}/manifest.yml" @src_file = "#{app_dir}/manifest.yml"
@feature_list = YAML.load(IO.read("#{@path}/#{@src_file}")) files_to_load = YAML.load(IO.read("#{@path}/#{@src_file}"))
@feature_list = files_to_load["features"]
@kernel_libraries = files_to_load["kernel_libs"] || []
end

def kernel_libraries
@kernel_libraries
end end


def features def features
Expand Down
5 changes: 4 additions & 1 deletion lib/calatrava/templates/droid/manifest.yml
@@ -1 +1,4 @@
- converter features:
- converter
kernel_libs:
# - assets/lib/underscore.js
5 changes: 4 additions & 1 deletion lib/calatrava/templates/ios/manifest.yml
@@ -1 +1,4 @@
- converter features:
- converter
kernel_libs:
# - assets/lib/underscore.js
5 changes: 4 additions & 1 deletion lib/calatrava/templates/web/manifest.yml
@@ -1 +1,4 @@
- converter features:
- converter
kernel_libs:
# - assets/lib/underscore.js
7 changes: 5 additions & 2 deletions spec/app_builder_spec.rb
Expand Up @@ -13,7 +13,8 @@
let(:manifest) { double('web mf', let(:manifest) { double('web mf',
:coffee_files => ['path/to/kernel.coffee', 'diff/path/shell.coffee'], :coffee_files => ['path/to/kernel.coffee', 'diff/path/shell.coffee'],
:kernel_bootstrap => ['path/to/kernel.coffee'], :kernel_bootstrap => ['path/to/kernel.coffee'],
:haml_files => ['diff/path/shell.haml']) } :haml_files => ['diff/path/shell.haml'],
:kernel_libraries => ['path/to/external/kernel_lib.js']) }


let(:app) { Calatrava::AppBuilder.new('app', 'app/build', manifest) } let(:app) { Calatrava::AppBuilder.new('app', 'app/build', manifest) }


Expand All @@ -32,9 +33,10 @@
end end


context '#load_file' do context '#load_file' do
subject { app.load_instructions.lines.to_a } subject { app.load_instructions.lines.to_a.each(&:chomp!) }


it { should include 'build/scripts/kernel.js' } it { should include 'build/scripts/kernel.js' }
it { should include 'build/scripts/kernel_lib.js' }
it { should_not include 'build/scripts/shell.js' } it { should_not include 'build/scripts/shell.js' }
end end


Expand All @@ -43,4 +45,5 @@


it { should include 'diff/path/shell.haml' } it { should include 'diff/path/shell.haml' }
end end

end end
20 changes: 19 additions & 1 deletion spec/manifest_spec.rb
Expand Up @@ -6,7 +6,7 @@


before(:each) do before(:each) do
create_dir 'app' create_dir 'app'
write_file 'app/manifest.yml', ['included'].to_yaml write_file 'app/manifest.yml', {'features' => ['included'], 'kernel_libs' => ['kernel_lib.js']}.to_yaml
end end


let(:features) { } let(:features) { }
Expand Down Expand Up @@ -59,4 +59,22 @@
it { should_not include 'shell_inc' } it { should_not include 'shell_inc' }
end end


context '#kernel_libraries' do
context "#when present" do
subject { manifest.kernel_libraries }

it { should include 'kernel_lib.js'}
end

context "#when not present" do
before do
write_file 'app/manifest.yml', {'features' => ['included'], 'kernel_libs' => nil}.to_yaml
end

subject { manifest.kernel_libraries }

it { should be_empty}
end
end

end end

0 comments on commit e19af8d

Please sign in to comment.