xmvc 0.1.8 → 0.1.9

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.
Files changed (39) hide show
  1. data/Rakefile +12 -3
  2. data/VERSION +1 -1
  3. data/lib/xmvc/api.rb +22 -31
  4. data/lib/xmvc/builder.rb +5 -22
  5. data/lib/xmvc/generator.rb +0 -2
  6. data/lib/xmvc/generators/app.rb +21 -18
  7. data/lib/xmvc/generators/boot.rb +19 -62
  8. data/lib/xmvc/generators/templates/app/public/config/application.js +2 -2
  9. data/lib/xmvc/generators/templates/index.html +22 -0
  10. data/lib/xmvc/helpers/sprockets.rb +25 -10
  11. data/lib/xmvc/vendor.rb +178 -15
  12. data/lib/xmvc.rb +31 -32
  13. data/test/app/public/javascripts/valid_vendor/valid_vendor-all-debug.js +1 -0
  14. data/test/app/test/app/vendor/ext/vendor.yml +19 -0
  15. data/test/app/vendor/ext/vendor.yml +19 -0
  16. data/test/app/vendor/valid_vendor/src/ValidVendor.js +1 -0
  17. data/test/app/vendor/valid_vendor/vendor.yml +4 -0
  18. data/test/helper.rb +7 -1
  19. data/test/lib/invalid_vendor/invalid_vendor.rb +15 -0
  20. data/test/lib/invalid_vendor/src/InvalidVendor.js +1 -0
  21. data/test/lib/nameless_vendor/nameless_vendor.rb +20 -0
  22. data/test/lib/nameless_vendor/src/ValidVendor.js +1 -0
  23. data/test/lib/nameless_vendor/vendor.yml +4 -0
  24. data/test/lib/valid_vendor/src/ValidVendor.js +1 -0
  25. data/test/lib/valid_vendor/valid_vendor.rb +18 -0
  26. data/test/lib/valid_vendor/vendor.yml +4 -0
  27. data/test/test_app_installer.rb +15 -0
  28. data/test/test_vendor_installer.rb +108 -0
  29. metadata +36 -15
  30. data/lib/xmvc/README +0 -20
  31. data/lib/xmvc/builders/all_builder.rb +0 -13
  32. data/lib/xmvc/builders/app_builder.rb +0 -36
  33. data/lib/xmvc/builders/base.rb +0 -138
  34. data/lib/xmvc/builders/css_builder.rb +0 -34
  35. data/lib/xmvc/builders/mvc_builder.rb +0 -33
  36. data/lib/xmvc/builders/plugin_builder.rb +0 -53
  37. data/lib/xmvc/builders/vendor.rb +0 -85
  38. data/lib/xmvc/plugin.rb +0 -102
  39. data/test/test_extjs-core.rb +0 -7
@@ -1,138 +0,0 @@
1
-
2
- module ExtJS
3
- module MVC
4
- module Builder
5
- class Base
6
-
7
- # Subclasses must implement this method to return the name of the file that concatenated output will be saved to
8
- def output_filename
9
- raise
10
- end
11
-
12
- # Does the actual building - just concatenates file_list and optionally minifies
13
- def build
14
- concatenate(file_list, output_filename)
15
- system('growlnotify -m "Built ' + name + '"')
16
-
17
- if should_minify
18
- minify output_filename
19
- system('growlnotify -m "Minified ' + name + '"')
20
- end
21
-
22
- puts message
23
- end
24
-
25
- # Indicates whether the outputted filename should also be minified (defaults to false)
26
- def should_minify
27
- false
28
- end
29
-
30
- def name
31
- "Unknown Package"
32
- end
33
-
34
- def message
35
- "Build complete"
36
- end
37
-
38
- def description
39
- directory_name
40
- end
41
-
42
- # Returns an array of all files to be concatenated, in the order they should be included
43
- def file_list
44
- has_build_file? ? order_from_build_file : guess_build_order
45
- end
46
-
47
- def has_build_file?
48
- File.exists?(build_file_name)
49
- end
50
-
51
- def build_file_name
52
- "#{directory_name}/build"
53
- end
54
-
55
- # Subclasses can override this method to return the string name of the directory under while the file_list resides
56
- def directory_name
57
- "./"
58
- end
59
-
60
- # Returns an array of all of the files listed in the build file
61
- def order_from_build_file
62
- build_files = []
63
- file = File.open(build_file_name, "r")
64
-
65
- while (line = file.gets)
66
- line.gsub!(/\n/, '')
67
- next if line =~ /^#/ || line.length.zero?
68
-
69
- filename = "#{directory_name}/#{line}"
70
-
71
- if File.exists?(filename)
72
- build_files.push(filename) unless build_files.include?(filename)
73
- else
74
- js_files_in_glob(filename).each {|filename| build_files.push(filename) unless build_files.include?(filename)}
75
- end
76
- end
77
-
78
- build_files
79
- end
80
-
81
- # Returns an array of all the .js files found in the plugin dir, in the order in which they are found
82
- # (ignores the 'PluginName-all.js' file)
83
- def guess_build_order
84
- js_files_in_glob("#{directory_name}/**/*.js")
85
- end
86
-
87
- def js_files_in_glob(glob)
88
- Dir[glob].select {|fileName| Regexp.new(output_filename).match(fileName).nil?}
89
- end
90
-
91
- private
92
-
93
- # Concatenates an array of files together and saves
94
- def concatenate(files, concatenated_filename, baseDir = './')
95
- #remove old files, create blank ones again
96
- if File.exists?(concatenated_filename)
97
- File.delete(concatenated_filename)
98
- # puts "Deleted old #{concatenated_filename}"
99
- end
100
- FileUtils.touch(concatenated_filename)
101
-
102
- count = 0
103
- file = File.open(concatenated_filename, 'w') do |f|
104
- files.each do |i|
105
- # remove the directory the app is in if add_dir is supplied
106
- i = i.gsub(Regexp.new(ENV['app_dir']), '').gsub(/$(\/*)(.*)/, '\2') if ENV['app_dir']
107
-
108
- f.puts(IO.read(File.join(baseDir, i)))
109
- f.puts("\n")
110
- count += 1
111
- end
112
- end
113
-
114
- # puts "Concatenated #{count} files into #{concatenated_filename}"
115
- # puts
116
- end
117
-
118
- # Minifies a file using YUI compressor
119
- def minify(filename, minified_filename = nil)
120
- if minified_filename.nil?
121
- minified_filename = filename.gsub(/\.js$/, '-min.js')
122
- end
123
-
124
- if File.exists?(minified_filename)
125
- FileUtils.rm(minified_filename)
126
- # puts "Deleted old #{minified_filename}"
127
- end
128
-
129
- system("java -jar vendor/yui-compressor/build/yuicompressor-2.4.jar #{filename} -o #{minified_filename}")
130
-
131
- # puts "Created minified file #{minified_filename}"
132
- # puts
133
- end
134
-
135
- end
136
- end
137
- end
138
- end
@@ -1,34 +0,0 @@
1
- module Xmvc
2
- class CssBuilder < Builder
3
- #def self.instances(args = [])
4
- # [ExtMVC::CssBuilder.new]
5
- #end
6
-
7
- def file_list
8
- # build to production environment
9
- #environment = ExtMVC.mvc_development_environment
10
-
11
- #return ExtJS::MVC.css_files_for(environment)
12
- end
13
-
14
- def name
15
- "Ext MVC Application Stylesheets"
16
- end
17
-
18
- def message
19
- "Built #{name}"
20
- end
21
-
22
- def description
23
- "Your #{name}"
24
- end
25
-
26
- def output_filename
27
- "public/stylesheets/application-all.css"
28
- end
29
-
30
- def directory_name
31
- "public/stylesheets/"
32
- end
33
- end
34
- end
@@ -1,33 +0,0 @@
1
- module Ext
2
- module MVC
3
- class MVCBuilder < Builder
4
- def self.instances(args = [])
5
- [ExtMVC::MVCBuilder.new]
6
- end
7
-
8
- def output_filename
9
- "#{directory_name}/ext-mvc-all.js"
10
- end
11
-
12
- def directory_name
13
- "vendor/mvc"
14
- end
15
-
16
- def should_minify
17
- true
18
- end
19
-
20
- def name
21
- "Ext MVC"
22
- end
23
-
24
- def message
25
- "Built #{name}"
26
- end
27
-
28
- def description
29
- "The #{name} framework (#{directory_name})"
30
- end
31
- end
32
- end
33
- end
@@ -1,53 +0,0 @@
1
- module ExtJS
2
- module MVC
3
- class PluginBuilder < Builder
4
- # returns an array of PluginBuilder instances based on input from the command line.
5
- # The sole argument should be an array, where the first element will usually be a plugin name, or 'all'
6
- def self.instances(args = [])
7
- name = args[0] || 'all'
8
-
9
- if name == 'all'
10
- self.all_plugin_names.collect {|name| ExtMVC::PluginBuilder.new(name)}
11
- else
12
- [ExtMVC::PluginBuilder.new(name)]
13
- end
14
- end
15
-
16
- attr_accessor :name
17
-
18
- def initialize(name)
19
- @name = name
20
- end
21
-
22
- def output_filename
23
- "#{directory_name}/#{name}-all.js"
24
- end
25
-
26
- def message
27
- "Built the #{name} plugin"
28
- end
29
-
30
- def description
31
- "The #{name} plugin (#{directory_name})"
32
- end
33
-
34
- def directory_name
35
- "#{ExtMVC::PluginBuilder.plugins_directory}/#{@name}"
36
- end
37
-
38
- # The plugins directory, relative to the directory the build command is run from
39
- def self.plugins_directory
40
- "vendor/plugins"
41
- end
42
-
43
- private
44
-
45
- #Gets the name of each plugin directory inside vendor/plugins and calls self.plugin with it
46
- def self.all_plugin_names
47
- Dir.entries(self.plugins_directory).select {|fileName|
48
- File.directory?("#{self.plugins_directory}/#{fileName}") && (fileName =~ /^\./) != 0
49
- }
50
- end
51
- end
52
- end
53
- end
@@ -1,85 +0,0 @@
1
- module Xmvc
2
- class Builder
3
- class Vendor < Thor
4
- include Thor::Actions
5
-
6
- def self.source_root
7
- Xmvc.public_path
8
- end
9
-
10
- desc "app", "Build application-host's assets"
11
- def app(environment)
12
- pkgs = []
13
-
14
- Xmvc.secretary.reset!({
15
- :source_files => Xmvc::Config[:javascripts]
16
- })
17
-
18
- filename = Xmvc.public_build_path(:js, "app", nil, "debug")
19
- create_file(filename, Xmvc.secretary.concatenation)
20
-
21
- pkgs << {
22
- :vendor => :host,
23
- :filename => filename,
24
- :source_files => Xmvc.secretary.preprocessor.source_files
25
- }
26
-
27
- end
28
-
29
- desc "build", "Build a vendor's assets"
30
- def build(spec, pkgs=[])
31
- if spec["dependencies"]
32
- spec["dependencies"].each do |vendor|
33
- each_vendor do |vspec|
34
- builder = Vendor.new([], {})
35
- builder.invoke("build", [vspec, pkgs])
36
- end
37
- end
38
- end
39
-
40
- Xmvc.secretary.reset!({
41
- :source_files => spec["javascripts"]
42
- })
43
-
44
- filename = Xmvc.public_build_path(:js, spec["name"], spec["version"], "debug")
45
-
46
- create_file(filename, Xmvc.secretary.concatenation)
47
- pkgs << {
48
- :vendor => spec,
49
- :filename => filename,
50
- :source_files => Xmvc.secretary.preprocessor.source_files
51
- }
52
-
53
- end
54
-
55
- private
56
-
57
- def each_vendor
58
- vendors = []
59
- Dir["vendor/*"].map {|vendor|
60
- inside(vendor) do
61
- if File.exists?("vendor.yml")
62
- yield YAML.load_file("vendor.yml")
63
- end
64
- end
65
- }
66
- end
67
-
68
- def vendor_assets(type, spec)
69
- path = (spec["host"]) ? "#{spec['host']}/#{spec['name']}" : vendor_name(spec)
70
- spec[type].map {|file|
71
- File.join(path, file)
72
- }
73
- end
74
-
75
- def vendor_name(spec)
76
- (spec["version"]) ? "#{spec['name']}-#{spec['version']}" : spec['name']
77
- end
78
-
79
-
80
-
81
-
82
- end
83
- end
84
- end
85
-
data/lib/xmvc/plugin.rb DELETED
@@ -1,102 +0,0 @@
1
- # Is this really required??
2
- #
3
- #require 'ftools'
4
- module Xmvc
5
- class Plugin
6
- def self.dispatch
7
- meth = ARGV.shift.downcase
8
- name = ARGV.shift
9
-
10
- if name == 'all'
11
- self.send("#{meth}_all")
12
- else
13
- ExtMVC::Plugin.new(name).send(meth)
14
- end
15
- end
16
-
17
- def self.install_all
18
- self.all_plugins.each {|pluginName| ExtMVC::Plugin.new(pluginName).install}
19
- end
20
-
21
- def self.uninstall_all
22
- self.all_plugins.each {|pluginName| ExtMVC::Plugin.new(pluginName).uninstall}
23
- end
24
-
25
- def self.all_plugins
26
- pluginsDir = 'vendor/plugins'
27
-
28
- #Gets the name of each plugin directory inside vendor/plugins and calls self.plugin with it
29
- Dir.entries(pluginsDir).select {|fileName|
30
- File.directory?("#{pluginsDir}/#{fileName}") && (fileName =~ /^\./) != 0
31
- }
32
- end
33
-
34
- attr_reader :name, :type, :directory
35
-
36
- def initialize name
37
- @name = @directory = name
38
- @type = @name =~ /git:\/\// ? 'git' : 'dir'
39
-
40
- @public_directory = "vendor/plugins/#{@name}/public"
41
- end
42
-
43
- def install
44
- install_assets
45
- end
46
-
47
- def install_assets
48
- install_assets_from_directory(@public_directory) if File.exists?(@public_directory)
49
- end
50
-
51
- def uninstall
52
- if File.exists?(@public_directory)
53
-
54
- end
55
- end
56
-
57
- private
58
- #installs all assets from the given directory and subdirs into the main /public folder
59
- def install_assets_from_directory(directory)
60
- directory ||= @public_directory
61
-
62
- find_assets_in_directory(directory).each do |f|
63
- new_asset = asset_new_location_name(f)
64
- if File.directory?(f)
65
- unless File.exists?(new_asset)
66
- Dir.mkdir(new_asset)
67
- puts "Created directory: " + new_asset
68
- end
69
- else
70
- action = File.exists?(new_asset) ? 'Updated' : 'Installed'
71
- File.copy(f, new_asset)
72
- puts action + " file: " + new_asset
73
- end
74
- end
75
- end
76
-
77
- #recursively finds assets in directories under /public inside the plugin
78
- def find_assets_in_directory(directory)
79
- files = []
80
-
81
- Dir.entries(directory).each do |e|
82
- filename = File.join(directory, e)
83
- next if ['.', '..'].include?(filename.split('/').last.to_s)
84
-
85
- files.push(filename)
86
- files.concat(find_assets_in_directory(filename)) if File.directory?(filename)
87
- end
88
-
89
- return files
90
- end
91
-
92
- #i.e. vendor/plugins/MyPlugin/public/images/image.gif becomes public/images/image.gif
93
- def asset_new_location_name(filename)
94
- pieces = filename.split("/")
95
- if index = pieces.index('public')
96
- File.join(pieces.slice(index, pieces.size))
97
- else
98
- filename
99
- end
100
- end
101
- end
102
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestExtjsCore < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end