ymdp 0.0.3

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 (37) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +17 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/lib/application_view/application_view.rb +210 -0
  8. data/lib/application_view/asset_tag_helper.rb +106 -0
  9. data/lib/application_view/commands/generate.rb +3 -0
  10. data/lib/application_view/compiler/template_compiler.rb +417 -0
  11. data/lib/application_view/config.rb +39 -0
  12. data/lib/application_view/environment.rb +29 -0
  13. data/lib/application_view/generator/base.rb +15 -0
  14. data/lib/application_view/generator/templates/javascript.js +51 -0
  15. data/lib/application_view/generator/templates/stylesheet.css +5 -0
  16. data/lib/application_view/generator/templates/translation.pres +8 -0
  17. data/lib/application_view/generator/templates/view.html.haml +8 -0
  18. data/lib/application_view/generator/view.rb +170 -0
  19. data/lib/application_view/helpers.rb +4 -0
  20. data/lib/application_view/processor/compressor.rb +81 -0
  21. data/lib/application_view/processor/processor.rb +132 -0
  22. data/lib/application_view/processor/validator.rb +125 -0
  23. data/lib/application_view/support/file.rb +54 -0
  24. data/lib/application_view/support/form_post.rb +58 -0
  25. data/lib/application_view/support/g.rb +11 -0
  26. data/lib/application_view/support/growl.rb +36 -0
  27. data/lib/application_view/support/timer.rb +40 -0
  28. data/lib/application_view/support/w3c.rb +22 -0
  29. data/lib/application_view/tag_helper.rb +147 -0
  30. data/lib/application_view/translator/base.rb +387 -0
  31. data/lib/application_view/translator/blank.rb +58 -0
  32. data/lib/application_view/translator/ymdp_translate.rb +92 -0
  33. data/lib/ymdp.rb +1 -0
  34. data/test/helper.rb +10 -0
  35. data/test/test_ymdp.rb +4 -0
  36. data/ymdp.gemspec +77 -0
  37. metadata +92 -0
@@ -0,0 +1,29 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+ require 'net/http'
4
+ require 'optparse'
5
+
6
+ require 'vendor/gems/environment'
7
+ Bundler.require_env
8
+
9
+ require 'constants'
10
+
11
+ # load application
12
+ #
13
+ Dir["#{APPLICATION_PATH}/*.rb"].each do |path|
14
+ require path
15
+ end
16
+
17
+ # load support
18
+ #
19
+ Dir["#{APPLICATION_PATH}/support/*.rb"].each do |path|
20
+ require path
21
+ end
22
+
23
+ # load everything in the lib directory
24
+ #
25
+ Dir["#{BASE_PATH}/lib/**/*.rb"].each do |path|
26
+ require path unless path == File.expand_path(__FILE__)
27
+ end
28
+
29
+ require "#{APPLICATION_PATH}/support/file"
@@ -0,0 +1,15 @@
1
+ require 'generator/view'
2
+
3
+ module ApplicationView
4
+ module Generator
5
+ class Base
6
+ def self.generate(args)
7
+ @command = args.shift
8
+
9
+ if @command == "view"
10
+ ApplicationView::Generator::View.new(args).generate
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,51 @@
1
+ /*
2
+ INIT
3
+
4
+ local to each view. Launched automatically when the window is loaded.
5
+ */
6
+
7
+ // Adds behaviors/observers to elements on the page
8
+ //
9
+ // YAHOO.init.addBehaviors = function() {
10
+ // // overwrite this function locally
11
+ // };
12
+
13
+ // To be run before any other initializers have run.
14
+ //
15
+ // YAHOO.init.before = function() {
16
+ // // overwrite this function locally
17
+ // };
18
+
19
+ // A/B testing hook. Runs before the page content is shown.
20
+ //
21
+ // A/B testing is disabled by default.
22
+ //
23
+ // YAHOO.init.abTesting = function() {
24
+ // // to enable A/B testing in your view, overwrite this file locally.
25
+ // //
26
+ // // be sure to finish your post-Ajax callback with YAHOO.init.show()
27
+ // //
28
+ // YAHOO.init.show();
29
+ // };
30
+
31
+ // Post-initalizer. Runs after startup.
32
+ //
33
+ // YAHOO.init.after = function() {
34
+ // // overwrite this function locally
35
+ // };
36
+
37
+ YAHOO.init.local = function() {
38
+ // put whatever you need in here
39
+ // make sure your final callback is the following:
40
+ //
41
+ YAHOO.init.finish();
42
+ };
43
+
44
+ I18n.localTranslations = function() {
45
+ // add local translation functions here
46
+ };
47
+
48
+ // hide the loading screen and show the main body of the summary
49
+ // YAHOO.init.show = function() {
50
+ // overwrite this function only if necessary
51
+ // };
@@ -0,0 +1,5 @@
1
+ /*
2
+
3
+ <%= @view.capitalize %> view styles
4
+
5
+ */
@@ -0,0 +1,8 @@
1
+ # REMOVE 'NEW' FROM THIS FILENAME WHEN PROFESSIONAL TRANSLATIONS HAVE BEEN DONE
2
+ #
3
+ # <%= @view.capitalize %> view resource file
4
+ #
5
+
6
+ <%= @view.upcase %>_HEADING=<%= @view.capitalize %>
7
+
8
+ <%= @view.upcase %>_SUBHEAD=
@@ -0,0 +1,8 @@
1
+ <%= "%h1##{@view.downcase}_heading.t" %>
2
+
3
+
4
+ <%= "%h2##{@view.downcase}_subhead.t" %>
5
+
6
+
7
+ <%= "%p Content goes here" %>
8
+
@@ -0,0 +1,170 @@
1
+ require 'support/file'
2
+ require 'translator/base'
3
+ require 'erb'
4
+
5
+ module ApplicationView
6
+ module Generator
7
+ module Snippets
8
+ def launcher_method(view)
9
+ view = view.downcase
10
+ class_name = view.capitalize
11
+ <<-OUTPUT
12
+
13
+ Launcher.launch#{class_name} = function() {
14
+ Launcher.launchTab("#{view}", "#{class_name}");
15
+ };
16
+ OUTPUT
17
+ end
18
+ end
19
+
20
+ module Templates
21
+ class Base
22
+ include ApplicationView::FileSupport
23
+
24
+ attr_accessor :view
25
+
26
+ def initialize(view)
27
+ @view = view
28
+ end
29
+
30
+ def generate
31
+ write_processed_template
32
+ end
33
+
34
+ def template_dir
35
+ "#{APPLICATION_PATH}/generator/templates"
36
+ end
37
+
38
+ def process_template(template)
39
+ ERB.new(template, 0, "%<>").result(binding)
40
+ end
41
+
42
+ def processed_template
43
+ result = ""
44
+ File.open(full_template_path) do |f|
45
+ template = f.read
46
+ result = process_template(template)
47
+ end
48
+ result
49
+ end
50
+
51
+ def write_processed_template
52
+ write_to_file
53
+ end
54
+
55
+ def destination_path
56
+ "#{destination_dir}/#{destination_filename}"
57
+ end
58
+
59
+ def full_template_path
60
+ "#{template_dir}/#{template_filename}"
61
+ end
62
+
63
+ def write_processed_template
64
+ if confirm_overwrite(destination_path)
65
+ append_to_file(destination_path, processed_template)
66
+ end
67
+ end
68
+
69
+ def append_to_file(file, content)
70
+ File.open(file, "a") do |f|
71
+ puts " #{display_path(file)} writing . . ."
72
+ f.puts content
73
+ end
74
+ end
75
+ end
76
+
77
+ class View < Base
78
+ def template_filename
79
+ "view.html.haml"
80
+ end
81
+
82
+ def destination_filename
83
+ "#{view}.html.haml"
84
+ end
85
+
86
+ def destination_dir
87
+ "#{BASE_PATH}/app/views"
88
+ end
89
+ end
90
+
91
+ class JavaScript < Base
92
+ def template_filename
93
+ "javascript.js"
94
+ end
95
+
96
+ def destination_dir
97
+ "#{BASE_PATH}/app/javascripts"
98
+ end
99
+
100
+ def destination_filename
101
+ "#{view}.js"
102
+ end
103
+ end
104
+
105
+ class Stylesheet < Base
106
+ def template_filename
107
+ "stylesheet.css"
108
+ end
109
+
110
+ def destination_dir
111
+ "#{BASE_PATH}/app/stylesheets"
112
+ end
113
+
114
+ def destination_filename
115
+ "#{view}.css"
116
+ end
117
+ end
118
+
119
+ class Translation < Base
120
+ def template_filename
121
+ "translation.pres"
122
+ end
123
+
124
+ def destination_dir
125
+ "#{BASE_PATH}/app/assets/yrb/en-US"
126
+ end
127
+
128
+ def destination_filename
129
+ "new_#{view}_en-US.pres"
130
+ end
131
+ end
132
+
133
+ class Modifications < Base
134
+ include Snippets
135
+
136
+ def generate
137
+ content = launcher_method(view)
138
+ append_to_file(destination_path, content)
139
+ end
140
+
141
+ def destination_dir
142
+ "#{BASE_PATH}/app/javascripts"
143
+ end
144
+
145
+ def destination_filename
146
+ "launcher.js"
147
+ end
148
+ end
149
+ end
150
+
151
+ class View
152
+ attr_accessor :view
153
+
154
+ def initialize(args)
155
+ @view = args.first
156
+ end
157
+
158
+ def generate
159
+ puts "Create a new view: #{view}"
160
+
161
+ Templates::View.new(view).generate
162
+ Templates::JavaScript.new(view).generate
163
+ Templates::Stylesheet.new(view).generate
164
+ Templates::Translation.new(view).generate
165
+ Templates::Modifications.new(view).generate
166
+ ApplicationView::Translator::YRB.translate
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,4 @@
1
+ Dir["./app/helpers/*_helper.rb"].each do |path|
2
+ require path
3
+ end
4
+
@@ -0,0 +1,81 @@
1
+ require 'support/file'
2
+
3
+ module ApplicationView
4
+ module Compressor
5
+ class Base
6
+ extend ApplicationView::Config
7
+ extend ApplicationView::FileSupport
8
+
9
+ def self.compress(path, options={})
10
+ compressed_display_path = display_path(path)
11
+ compressed_path = "#{path}.min"
12
+
13
+ options["type"] ||= "js"
14
+
15
+ unless File.exists?(compressed_path)
16
+ $stdout.print " #{compressed_display_path} compressing . . . "
17
+ compressed = ''
18
+
19
+ if !obfuscate?
20
+ options["nomunge"] = ""
21
+ end
22
+ if verbose?
23
+ options["verbose"] = ""
24
+ end
25
+ options["charset"] = "utf-8"
26
+
27
+ if options["type"].to_s == "js" && !options["preserve_semi"]
28
+ options["preserve-semi"] = ""
29
+ end
30
+
31
+ options_string = options.map {|k,v| "--#{k} #{v}"}.join(" ")
32
+
33
+ result = `java -jar ./script/yuicompressor-2.4.2.jar #{options_string} #{path} -o #{compressed_path} 2>&1`
34
+
35
+ result.split("\n").each do |line|
36
+ if line =~ /\[ERROR\] (\d+):(\d+):(.*)/
37
+ line_number = $1.to_i
38
+ error = "Error at #{compressed_display_path} line #{line_number} character #{$2}: #{$3}"
39
+ error += get_line_from_file(path, line_number)
40
+
41
+ $stdout.puts error
42
+ growl(error)
43
+ end
44
+ end
45
+
46
+ if result =~ /ERROR/
47
+ raise "JavaScript errors in #{compressed_display_path}"
48
+ else
49
+ $stdout.puts "OK"
50
+ end
51
+ end
52
+
53
+ if File.exists?(compressed_path)
54
+ File.open(compressed_path) do |c|
55
+ compressed = c.read
56
+ end
57
+ else
58
+ raise "File does not exist: #{compressed_display_path}"
59
+ end
60
+
61
+ compressed
62
+ end
63
+ end
64
+
65
+ class Stylesheet < Base
66
+ def self.compress(path)
67
+ if compress_css?
68
+ super(path, "type" => "css")
69
+ end
70
+ end
71
+ end
72
+
73
+ class JavaScript < Base
74
+ def self.compress(filename)
75
+ if compress_embedded_js?
76
+ super(filename, "type" => "js")
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,132 @@
1
+ require 'support/file'
2
+ require 'haml'
3
+
4
+ module ApplicationView
5
+ module Renderer
6
+ class Base
7
+ end
8
+
9
+ class Haml < Base
10
+ def self.scope
11
+ ApplicationView::ViewHelpers
12
+ end
13
+
14
+ def self.render(filename)
15
+ options = {}
16
+ ::Haml::Engine.new(filename, options).render(scope)
17
+ end
18
+ end
19
+
20
+ class ERB < Base
21
+ def self.scope
22
+ ApplicationView::ViewHelpers.get_binding
23
+ end
24
+
25
+ def self.render(filename)
26
+ ::ERB.new(filename, 0, "%<>").result(scope)
27
+ end
28
+ end
29
+ end
30
+
31
+ module Processor
32
+ class Base
33
+ extend ApplicationView::Config
34
+ extend ApplicationView::FileSupport
35
+
36
+ def self.render(params)
37
+ output = []
38
+ tags = true
39
+ if params[:tags] == false
40
+ tags = false
41
+ end
42
+ if params[:partial]
43
+ # params[:partial].to_a.each do |partial|
44
+ # output << render_partial(params)
45
+ output << Partial.render(params)
46
+ # end
47
+ end
48
+ # if params[:javascript]
49
+ # output << "<script type='text/javascript'>" if tags
50
+ # output << render_javascripts(params)
51
+ # output << "</script>" if tags
52
+ # end
53
+ # if params[:stylesheet]
54
+ # # params[:stylesheet].to_a.each do |stylesheet|
55
+ # output << render_stylesheet(params)
56
+ # # end
57
+ # end
58
+ output.join("\n")
59
+ end
60
+
61
+ def self.render_partial(params)
62
+ Partial.render(params)
63
+ end
64
+
65
+ def self.render_javascripts(params)
66
+ JavaScript.render(params)
67
+ end
68
+
69
+ def self.render_stylesheet(params)
70
+ Stylesheet.render(params)
71
+ end
72
+ end
73
+
74
+ class Partial < Base
75
+ def self.render(params)
76
+ filename = params[:partial]
77
+ output = ''
78
+ path = nil
79
+
80
+ path = find_partial(filename)
81
+
82
+ if path
83
+ output = process(path)
84
+ else
85
+ raise "Could not find partial: #{filename}"
86
+ end
87
+ output
88
+ end
89
+
90
+ def self.process(path)
91
+ output = ""
92
+
93
+ File.open(path) do |f|
94
+ template = f.read
95
+ if path =~ /haml$/
96
+ output = ApplicationView::Processor::Haml.render(template, path)
97
+ else
98
+ output = ApplicationView::Processor::ERB.render(template)
99
+ end
100
+ end
101
+
102
+ output
103
+ end
104
+
105
+ def self.find_partial(partial)
106
+ path = nil
107
+ ["views", "views/shared"].each do |dir|
108
+ basic_path = "#{BASE_PATH}/app/#{dir}/_#{partial}.html"
109
+
110
+ ["", ".haml", ".erb"].each do |extension|
111
+ if File.exists?(basic_path + extension)
112
+ path ||= basic_path + extension
113
+ end
114
+ end
115
+ end
116
+ path
117
+ end
118
+ end
119
+
120
+ class JavaScript < Base
121
+ def self.render(params)
122
+ puts "Rendering partial"
123
+ end
124
+ end
125
+
126
+ class Stylesheet < Base
127
+ def self.render(params)
128
+ puts "Rendering partial"
129
+ end
130
+ end
131
+ end
132
+ end