ezcript 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ == Wed Jun 08 16:31:10 +0800 2011 Melvin Sembrano <melvinsembrano@gmail.com>
2
+
3
+ * Created Ezcript
@@ -0,0 +1,9 @@
1
+ Ezcript readme
2
+ =========================
3
+
4
+ Decription
5
+ --------------------------
6
+
7
+ Usage
8
+ --------------------------
9
+
@@ -0,0 +1,36 @@
1
+ begin
2
+ require "rubygems"
3
+ require "bundler"
4
+ rescue LoadError
5
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
6
+ end
7
+
8
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("1.0.0")
9
+ raise RuntimeError, "Your bundler version is too old for Mail" +
10
+ "Run `gem install bundler` to upgrade."
11
+ end
12
+
13
+ begin
14
+ # Set up load paths for all bundled gems
15
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../Gemfile", __FILE__)
16
+ Bundler.setup
17
+ rescue Bundler::GemNotFound
18
+ raise RuntimeError, "Bundler couldn't find some gems." +
19
+ "Did you run `bundle install`?"
20
+ end
21
+
22
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
23
+
24
+ require 'rspec/core/rake_task'
25
+ RSpec::Core::RakeTask.new(:spec)
26
+ task :default => :spec
27
+
28
+ require "ezcript/version"
29
+
30
+ task :build do
31
+ system "gem build ezcript.gemspec"
32
+ end
33
+
34
+ task :release => :build do
35
+ system "gem push ezcript-#{Ezcript::VERSION::STRING}"
36
+ end
@@ -0,0 +1,4 @@
1
+ major:0
2
+ minor:0
3
+ patch:1
4
+ build:
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ module Ezcript
3
+ require 'ezcript/version'
4
+ require 'ezcript/application_helper_extension'
5
+ require 'ezcript/minifier/stylesheet'
6
+ end
@@ -0,0 +1,166 @@
1
+ module Ezcript
2
+ module ApplicationHelperExtension
3
+ def self.included(base)
4
+ base.send(:include, InstanceMethods)
5
+ end
6
+
7
+ module InstanceMethods
8
+
9
+ # yield for content_for, but will display default contents if content_for is not given
10
+ def yield_or_inline(yield_name, partial_name = nil, &block)
11
+ if @_content_for[yield_name] && !@_content_for[yield_name].empty?
12
+ @_content_for[yield_name]
13
+ else
14
+ if block_given?
15
+ render :inline => capture(&block)
16
+ else
17
+ render :partial => partial_name if partial_name
18
+ end
19
+ end
20
+ end
21
+
22
+ #If declared will include "controller#scripts and controller#action_scripts to the layout"
23
+ def yield_local_scripts
24
+ scripts = []
25
+ if "production".eql?(Rails.env)
26
+ js_cache_dir = File.join(Rails.root, "tmp", "cache", "js")
27
+ FileUtils.mkdir_p(js_cache_dir) unless File.exist?(js_cache_dir)
28
+ end
29
+
30
+ ["scripts", "#{action_name}_scripts"].each do |f|
31
+ partial_src = File.join(Rails.root, "app", "views", controller_name, "_#{f}.js.erb")
32
+ if File.exist?(partial_src)
33
+
34
+ src = render(:partial => "#{controller_name}/#{f}.js")
35
+
36
+ if "production".eql?(Rails.env)
37
+ js_src = File.join(js_cache_dir, "#{controller_name}_#{File.basename(f, ".erb")}.min.js")
38
+ unless File.exist?(js_src)
39
+ File.open(js_src, "w") {|js_f| js_f.puts(JSMin.minify(src))}
40
+ end
41
+ src = render(:file => js_src)
42
+ end
43
+ scripts << src
44
+ end
45
+ end
46
+ render :inline => scripts.join("\n")
47
+ end
48
+
49
+ def yield_local_styles
50
+ scripts = []
51
+ ["styles", "#{action_name}_styles"].each do |f|
52
+ scripts << render(:partial => "#{controller_name}/#{f}.css") if File.exist?(File.join(Rails.root, "app", "views", controller_name, "_#{f}.css.erb"))
53
+ end
54
+ render :inline => scripts.join("\n")
55
+ end
56
+
57
+ =begin
58
+ def render_minified_style(source, opt={})
59
+ options = {:type => "text/css"}.merge(opt)
60
+ source = "#{Rails.root}/public/assets/stylesheets/#{source}"
61
+ source << ".css" unless source.end_with?(".css")
62
+ if ["staging","production"].include?(Rails.env)
63
+ css_cache_dir = File.join(Rails.root, "tmp", "cache", "css")
64
+ FileUtils.mkdir_p(css_cache_dir) unless File.exist?(css_cache_dir)
65
+ src = File.join(css_cache_dir, File.basename(source))
66
+ unless File.exist?(src)
67
+ File.open(src, "w") {|f| f.puts(R3xt::Minifier::Stylesheet.new(source, true).minified) }
68
+ end
69
+ else
70
+ src = source
71
+ end
72
+ c = render(:file => src)
73
+ content_tag(:style, c.gsub("../images/", "#{Compass::Info.asset_dir}/images/"), options)
74
+ end
75
+
76
+ def render_minified_script(source, opt={})
77
+ options = {:type => "text/javascript"}.merge(opt)
78
+ source = "#{Rails.root}/public/assets/javascripts/#{source}"
79
+ source << ".js" unless source.end_with?(".js")
80
+ if ["staging","production"].include?(Rails.env)
81
+ js_cache_dir = File.join(Rails.root, "tmp", "cache", "js")
82
+ FileUtils.mkdir_p(js_cache_dir) unless File.exist?(js_cache_dir)
83
+ src = File.join(js_cache_dir, File.basename(source))
84
+ unless File.exist?(src)
85
+ c = ""
86
+ File.open(source, "r") {|f| c = f.read}
87
+ File.open(src, "w") {|f| f.puts(JSMin.minify(c)) }
88
+ end
89
+ else
90
+ src = source
91
+ end
92
+ c = render(:file => src)
93
+ content_tag(:script, c, options)
94
+ end
95
+ =end
96
+
97
+ end
98
+ end
99
+ end
100
+
101
+ module ActionView
102
+ module Helpers
103
+ module AssetTagHelper
104
+
105
+ def stylesheet_tag(source, options)
106
+ s= "#{Compass::Info.asset_dir}/stylesheets/#{source}"
107
+ tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => html_escape(path_to_stylesheet(s)) }.merge(options), false, false)
108
+ end
109
+
110
+ def javascript_src_tag(source, options)
111
+ s= "#{Compass::Info.asset_dir}/javascripts/#{source}"
112
+ s << ".js" unless s.end_with?(".js")
113
+ content_tag("script", "", { "type" => Mime::JS, "src" => path_to_javascript(s) }.merge(options))
114
+ end
115
+
116
+ def image_tag(source, options = {})
117
+ options.symbolize_keys!
118
+
119
+ src = options[:src] = "#{Compass::Info.asset_dir}#{path_to_image(source)}"
120
+
121
+ unless src =~ /^cid:/
122
+ options[:alt] = options.fetch(:alt){ File.basename(src, '.*').capitalize }
123
+ end
124
+
125
+ if size = options.delete(:size)
126
+ options[:width], options[:height] = size.split("x") if size =~ %r{^\d+x\d+$}
127
+ end
128
+
129
+ if mouseover = options.delete(:mouseover)
130
+ options[:onmouseover] = "this.src='#{path_to_image(mouseover)}'"
131
+ options[:onmouseout] = "this.src='#{src}'"
132
+ end
133
+
134
+ tag("img", options)
135
+ end
136
+
137
+ def complete_link_to(*args, &block)
138
+ if block_given?
139
+ options = args.first || {}
140
+ html_options = args.second
141
+ link_to(capture(&block), options, html_options)
142
+ else
143
+ name = args[0]
144
+ options = args[1] || {}
145
+ html_options = args[2]
146
+
147
+ html_options = convert_options_to_data_attributes(options, html_options)
148
+ url = url_for(options)
149
+ url = File.join(Compass::Info.app_host, url).to_s unless url.downcase.starts_with?("http")
150
+
151
+ if html_options
152
+ html_options = html_options.stringify_keys
153
+ href = html_options['href']
154
+ tag_options = tag_options(html_options)
155
+ else
156
+ tag_options = nil
157
+ end
158
+
159
+ href_attr = "href=\"#{html_escape(url)}\"" unless href
160
+ "<a #{href_attr}#{tag_options}>#{(name || url)}</a>".html_safe
161
+ end
162
+ end
163
+
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,41 @@
1
+ # This code was extracted from Smurf
2
+ # https://github.com/thumblemonks/smurf
3
+ module Ezcript::Minifier
4
+ class Stylesheet
5
+ def self.minifies?(paths) !paths.grep(%r[\.css(\?\d+)?$]).empty?; end
6
+
7
+ def initialize(content, file=false)
8
+ if file
9
+ File.open(content, "r") {|f| content = f.read}
10
+ end
11
+ @content = content.nil? ? nil : minify(content)
12
+ end
13
+
14
+ def minified; @content; end
15
+
16
+ # TODO: deal with string values better (urls, content blocks, etc.)
17
+ def minify(content)
18
+ class << content; include Minifier; end
19
+ content.compress_whitespace.remove_comments.remove_spaces_outside_block.
20
+ remove_spaces_inside_block.trim_last_semicolon.strip
21
+ end
22
+
23
+ module Minifier
24
+ # .*? is a non-greedy match on anything
25
+ def compress_whitespace; compress!(/\s+/, ' '); end
26
+ def remove_comments; compress!(/\/\*.*?\*\/\s?/, ''); end
27
+ def remove_spaces_outside_block
28
+ compress!(/(\A|\})(.*?)\{/) { |m| m.gsub(/\s?([}{,])\s?/, '\1') }
29
+ end
30
+ def remove_spaces_inside_block
31
+ compress!(/\{(.*?)(?=\})/) do |m|
32
+ # remove spaces in the labels/attributes
33
+ m.gsub(/(?:\A|\s*;)(.*?)(?::\s*|\z)/) { |n| n.gsub(/\s/, '') }.strip
34
+ end
35
+ end
36
+ def trim_last_semicolon; compress!(/;(?=\})/, ''); end
37
+ private
38
+ def compress!(*args, &block) gsub!(*args, &block) || self; end
39
+ end
40
+ end # Stylesheet
41
+ end # Smurf
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ module Ezcript
3
+ module VERSION
4
+
5
+ version = {}
6
+ File.read(File.join(File.dirname(__FILE__), '../', 'VERSION')).each_line do |line|
7
+ type, value = line.chomp.split(":")
8
+ next if type =~ /^ +$/ || value =~ /^ +$/
9
+ version[type] = value
10
+ end
11
+
12
+ MAJOR = version['major']
13
+ MINOR = version['minor']
14
+ PATCH = version['patch']
15
+ BUILD = version['build']
16
+
17
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
18
+
19
+ def self.version
20
+ STRING
21
+ end
22
+
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ezcript
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Melvin Sembrano
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-08 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 25
30
+ segments:
31
+ - 2
32
+ - 5
33
+ - 1
34
+ version: 2.5.1
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: ZenTest
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 43
46
+ segments:
47
+ - 4
48
+ - 5
49
+ - 0
50
+ version: 4.5.0
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 49
62
+ segments:
63
+ - 0
64
+ - 8
65
+ - 7
66
+ version: 0.8.7
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 15
78
+ segments:
79
+ - 1
80
+ - 0
81
+ - 12
82
+ version: 1.0.12
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: jsmin
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 21
94
+ segments:
95
+ - 1
96
+ - 0
97
+ - 1
98
+ version: 1.0.1
99
+ type: :development
100
+ version_requirements: *id005
101
+ description: ""
102
+ email:
103
+ - melvinsembrano@gmail.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files:
109
+ - README.md
110
+ - CHANGELOG.md
111
+ files:
112
+ - README.md
113
+ - Rakefile
114
+ - lib/VERSION
115
+ - lib/ezcript.rb
116
+ - lib/ezcript/application_helper_extension.rb
117
+ - lib/ezcript/minifier/stylesheet.rb
118
+ - lib/ezcript/version.rb
119
+ - CHANGELOG.md
120
+ has_rdoc: true
121
+ homepage: http://github.com/melvinsembrano/ezcript
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.3.7
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: ""
154
+ test_files: []
155
+