Class: NinjsFramework
- Inherits:
-
Ninjs::Framework
- Object
- Ninjs::Framework
- NinjsFramework
- Defined in:
- lib/ninjs-framework.rb
Instance Attribute Summary collapse
-
#template_dir ⇒ Object
Returns the value of attribute template_dir.
Instance Method Summary collapse
- #compile_application_file(file) ⇒ Object
- #create(root, config) ⇒ Object
- #create_ninjs_application_file ⇒ Object
- #create_ninjs_lib_file ⇒ Object
- #create_utility_lib_file ⇒ Object
- #import_rakefile ⇒ Object
- #import_spec_file(src, dest) ⇒ Object
- #import_spec_files ⇒ Object
-
#initialize ⇒ NinjsFramework
constructor
A new instance of NinjsFramework.
- #update(root, config) ⇒ Object
- #update_application_file ⇒ Object
- #write_autoload(file) ⇒ Object
- #write_core(file) ⇒ Object
- #write_dependencies(file) ⇒ Object
Constructor Details
#initialize ⇒ NinjsFramework
Returns a new instance of NinjsFramework.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ninjs-framework.rb', line 5 def initialize @fw_root = File.('../', File.dirname(__FILE__)) @lib_dir = File.('lib', @fw_root) @template_dir = File.('ninjs-framework/templates', @lib_dir) super({ name: 'ninjs', manifest: [ 'application', 'elements', 'lib', 'models', 'modules', 'plugins', 'spec', 'spec/javascripts', 'spec/javascripts/support' ], defaults: { name: 'application', framework: 'ninjs', src_dir: 'modules', dest_dir: 'application', asset_root: '../', output: 'expanded', dependencies: ['<jquery/latest>'], autoload: ['../lib/utilities'], module_alias: 'm' } }) end |
Instance Attribute Details
#template_dir ⇒ Object
Returns the value of attribute template_dir.
3 4 5 |
# File 'lib/ninjs-framework.rb', line 3 def template_dir @template_dir end |
Instance Method Details
#compile_application_file(file) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/ninjs-framework.rb', line 146 def compile_application_file(file) begin ninjs_lib_secretary = Sprockets::Secretary.new( :root => Ninjs::BASE_DIR, :asset_root => @config[:asset_root], :load_path => ["repository"], source_files: ["#{file}"] ) application_file = ninjs_lib_secretary.concatenation ninjs_lib_secretary.install_assets application_file.save_to "#{file}" rescue Exception => error @errors = true puts Ninjs::Notification.error "Sprockets error: #{error.}" end end |
#create(root, config) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/ninjs-framework.rb', line 36 def create(root, config) @root = root @config = config create_ninjs_lib_file create_utility_lib_file create_ninjs_application_file import_rakefile import_spec_files end |
#create_ninjs_application_file ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/ninjs-framework.rb', line 77 def create_ninjs_application_file ninjs_lib = File.read("#{@root}/lib/nin.js") template = ERB.new(File.read(File.("#{@template_dir}/application.js.erb"))) File.open("#{@root}/application/#{@config[:name].downcase}.js", "w+") do |file| file << template.result(binding) end end |
#create_ninjs_lib_file ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ninjs-framework.rb', line 52 def create_ninjs_lib_file operation = File.exists?("#{@root}/lib/nin.js") ? 'updated' : 'created' ninjs_lib_secretary = Sprockets::Secretary.new( :root => "#{@lib_dir}/ninjs-framework", :load_path => ["core", "extensions", "utilities"], source_files: ["core/nin.js"] ) ninjs_lib_secretary.concatenation.save_to "#{@root}/lib/nin.js" puts Ninjs::Notification.added "lib/nin.js #{operation}" end |
#create_utility_lib_file ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ninjs-framework.rb', line 65 def create_utility_lib_file utility_lib_secretary = Sprockets::Secretary.new( root: "#{@lib_dir}/ninjs-framework", load_path: ["core", "extensions", "utilities"], source_files: ["utilities/all.js"] ) utility_lib_secretary.concatenation.save_to "#{@root}/lib/utilities.js" puts Ninjs::Notification.added "lib/utilities.js created" end |
#import_rakefile ⇒ Object
86 87 88 |
# File 'lib/ninjs-framework.rb', line 86 def import_rakefile FileUtils.cp "#{@fw_root}/Rakefile", "#{@root}/Rakefile" end |
#import_spec_file(src, dest) ⇒ Object
109 110 111 |
# File 'lib/ninjs-framework.rb', line 109 def import_spec_file(src, dest) FileUtils.cp "#{@fw_root}/#{src}", "#{@root}/#{dest}" end |
#import_spec_files ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ninjs-framework.rb', line 90 def import_spec_files { "spec/javascripts/application_spec.js" => 'spec/javascripts/', "spec/javascripts/array_utility_spec.js" => 'spec/javascripts/', "spec/javascripts/existence_spec.js" => 'spec/javascripts/', "spec/javascripts/extension_spec.js" => 'spec/javascripts/', "spec/javascripts/module_spec.js" => 'spec/javascripts/', "spec/javascripts/string_utility_spec.js" => 'spec/javascripts/', "spec/javascripts/support/jasmine_config.rb" => 'spec/javascripts/support', "spec/javascripts/support/jasmine_runner.rb" => 'spec/javascripts/support', "lib/ninjs-framework/templates/test-index.html.erb" => 'spec/index.html', "lib/ninjs-framework/templates/jasmine.yml.erb" => 'spec/javascripts/support/', "lib/ninjs-framework/assets/jasmine/jasmine-html.js" => 'spec/javascripts/support/', "lib/ninjs-framework/assets/jasmine/jasmine.css" => 'spec/javascripts/support/', "lib/ninjs-framework/assets/jasmine/jasmine.js" => 'spec/javascripts/support/', "lib/ninjs-framework/assets/jasmine/jasmine_favicon.png" => 'spec/javascripts/support/' }.each { |src, dest| import_spec_file src, dest } end |
#update(root, config) ⇒ Object
46 47 48 49 50 |
# File 'lib/ninjs-framework.rb', line 46 def update(root, config) @root = root @config = config update_application_file end |
#update_application_file ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ninjs-framework.rb', line 113 def update_application_file application_file = "#{@root}/#{@config[:dest_dir]}/#{@config[:name].downcase}.js" File.open(application_file, "w+") do |file| write_dependencies(file) write_core(file) write_autoload(file) end compile_application_file application_file end |
#write_autoload(file) ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/ninjs-framework.rb', line 138 def write_autoload(file) template = ERB.new(File.read(File.("#{@template_dir}/autoload.js.erb"))) @config[:autoload].each do |auto_file| is_repo = auto_file.match(/^\<.+\>$/) file << template.result(binding) end end |
#write_core(file) ⇒ Object
133 134 135 136 |
# File 'lib/ninjs-framework.rb', line 133 def write_core(file) template = ERB.new(File.read(File.("#{@template_dir}/core.js.erb"))) file << template.result(binding) end |
#write_dependencies(file) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/ninjs-framework.rb', line 125 def write_dependencies(file) template = ERB.new(File.read(File.("#{@template_dir}/dependency.js.erb"))) @config[:dependencies].each do |dependency| is_repo = dependency.match(/^\<.+\>$/) file << template.result(binding) end end |