merb-less-more 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ merb-less-more
2
+ ==============
3
+
4
+ A plugin for the Merb framework that provides support for Less css.
5
+
6
+ It's really just a port of the 'more' rails plugin.
data/Rakefile ADDED
@@ -0,0 +1,108 @@
1
+ GEM_NAME = "merb-less-more"
2
+ GEM_VERSION = "0.0.1"
3
+ AUTHOR = "Spencer Steffen"
4
+ EMAIL = "spencer@citrusme.com"
5
+ HOMEPAGE = "http://citrusme.com/"
6
+ SUMMARY = "Merb plugin for less css support."
7
+
8
+
9
+ begin
10
+ require 'jeweler'
11
+ Jeweler::Tasks.new do |gemspec|
12
+ gemspec.name = GEM_NAME
13
+ gemspec.platform = Gem::Platform::RUBY
14
+ gemspec.has_rdoc = true
15
+ gemspec.extra_rdoc_files = ["README", "LICENSE", "TODO"]
16
+ gemspec.summary = SUMMARY
17
+ gemspec.description = SUMMARY
18
+ gemspec.author = AUTHOR
19
+ gemspec.email = EMAIL
20
+ gemspec.homepage = HOMEPAGE
21
+ gemspec.add_dependency('merb-core', '>= 1.1.0')
22
+ gemspec.require_path = 'lib'
23
+ gemspec.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
24
+ end
25
+ Jeweler::GemcutterTasks.new
26
+ rescue LoadError
27
+ puts "Jeweler not available. Install it with: gem install jeweler"
28
+ end
29
+
30
+ #
31
+ #
32
+ #
33
+ #
34
+ #
35
+ #require 'rake/gempackagetask'
36
+ #
37
+ ##require 'merb-core'
38
+ ##require 'merb-core/tasks/merb'
39
+ #
40
+ #spec = Gem::Specification.new do |s|
41
+ #
42
+ #end
43
+ #
44
+ #
45
+ #begin
46
+ # require 'jeweler'
47
+ # Jeweler::Tasks.new do |gemspec|
48
+ # # Attributes omitted.
49
+ #
50
+ #
51
+ #
52
+ # puts "WTf #{gemspec}"
53
+ #
54
+ #
55
+ # end
56
+ # Jeweler::GemcutterTasks.new
57
+ #rescue LoadError
58
+ # puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
59
+ #end
60
+ #
61
+ #
62
+ ###Rake::GemPackageTask.new(spec) do |pkg|
63
+ ### pkg.gem_spec = spec
64
+ ###end
65
+ ###
66
+ ###desc "install the plugin as a gem"
67
+ ###task :build do
68
+ ### pkg.gem_spec = spec
69
+ ###
70
+ ### #Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
71
+ ###
72
+ ###
73
+ ###end
74
+ ####
75
+ ####desc "Uninstall the gem"
76
+ ####task :uninstall do
77
+ #### Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
78
+ ####end
79
+ ###
80
+ ###desc "Create a gemspec file"
81
+ ###task :gemspec do
82
+ ### File.open("#{GEM_NAME}.gemspec", "w") do |file|
83
+ ### file.puts spec.to_ruby
84
+ ### end
85
+ ###end
86
+ ###
87
+ ####begin
88
+ #### require 'spec'
89
+ #### require 'spec/rake/spectask'
90
+ ####
91
+ #### task :default => [ :spec ]
92
+ ####
93
+ #### desc 'Run specifications'
94
+ #### Spec::Rake::SpecTask.new(:spec) do |t|
95
+ #### t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
96
+ #### t.spec_opts << '--color' << '--format' << 'specdoc'
97
+ #### begin
98
+ #### require 'rcov'
99
+ #### t.rcov_opts << '--exclude' << 'spec'
100
+ #### t.rcov_opts << '--text-summary'
101
+ #### t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
102
+ #### rescue LoadError
103
+ #### # rcov not installed
104
+ #### end
105
+ #### end
106
+ ####rescue LoadError
107
+ #### # rspec not installed
108
+ ####end
data/TODO ADDED
@@ -0,0 +1 @@
1
+ TODO:
@@ -0,0 +1,7 @@
1
+ class Merb::Controller
2
+ before :generate_css_from_less
3
+
4
+ def generate_css_from_less
5
+ Less::More.generate_all
6
+ end
7
+ end
@@ -0,0 +1,142 @@
1
+ # Less::More provides methods for parsing LESS files in a rails application to CSS target files.
2
+ #
3
+ # When Less::More.parse is called, all files in Less::More.source_path will be parsed using LESS
4
+ # and saved as CSS files in Less::More.destination_path. If Less::More.compression is set to true,
5
+ # extra line breaks will be removed to compress the CSS files.
6
+ #
7
+ # By default, Less::More.parse will be called for each request in `development` environment and on
8
+ # application initialization in `production` environment.
9
+
10
+ begin
11
+ require 'less'
12
+ rescue LoadError => e
13
+ e.message << " (You may need to install the less gem)"
14
+ raise e
15
+ end
16
+
17
+ class Less::More
18
+ HEADER = %{/*\n\n\n\n\n\tThis file was auto generated by Less (http://lesscss.org). To change the contents of this file, edit %s instead.\n\n\n\n\n*/}
19
+
20
+ class << self
21
+ # Less::More.compression = true/false --- compress generated css ? (default: false)
22
+ # Less::More.header = true/false --- insert editing warning into css ? (default: true)
23
+ # Less::More.destination_path = 'css' --- put css into public/??? (default: stylesheets)
24
+ # Less::More.source_path = 'public/stylesheets/less' --- where do less files live? (default: app/stylesheets)
25
+ attr_writer :compression, :header, :destination_path, :source_path
26
+
27
+ def header
28
+ @header.nil? ? true : @header
29
+ end
30
+
31
+ def destination_path
32
+ @destination_path || 'stylesheets'
33
+ end
34
+
35
+ def source_path
36
+ @source_path || 'app/stylesheets'
37
+ end
38
+
39
+ def compression
40
+ @compression
41
+ end
42
+
43
+ # Generates the .css from a .less or .lss file in Less::More.source_path matching
44
+ # the given parameters.
45
+ #
46
+ # Less::More.generate("screen.less")
47
+ # Less::More.generate("subdirectories/here/homepage.less")
48
+ def generate(source)
49
+ generated = to_dot_css(path_to_destination(source))
50
+ path_to_source = File.join(Merb.root, source_path, source)
51
+
52
+ # check if the destination file exists, and compare the modified times to see if it needs to be written
53
+ if mtime(generated) >= mtime_including_imports(path_to_source)
54
+ # up to date, nothing to do!
55
+ else
56
+ # css file does not exist or is out of date
57
+ css = if File.extname(path_to_source) == ".css"
58
+ # vanilla css nothing to do!
59
+ File.read(path_to_source)
60
+ else
61
+ # less or lss file, compile it
62
+ css = compile(path_to_source)
63
+ css.delete!("\n") if compression # TODO: use real compression !
64
+ css = (HEADER % [File.join(source_path, source)]) << css if header
65
+ css
66
+ end
67
+
68
+ # write the css
69
+ FileUtils.mkdir_p File.dirname(generated)
70
+ File.open(generated, "w"){|f| f.write css }
71
+ end
72
+ end
73
+
74
+ # Generates all the .css files
75
+ def generate_all
76
+ all_less_files.each do |path|
77
+ generate(relative_to_source_path(path))
78
+ end
79
+ end
80
+
81
+ # Removes all generated css files.
82
+ def remove_all_generated
83
+ all_less_files.each do |path|
84
+ css_path = to_dot_css(relative_to_source_path(path))
85
+ css_file = path_to_destination(css_path)
86
+ File.delete(css_file) if File.file?(css_file)
87
+ end
88
+ end
89
+
90
+ # Array of paths of less source files.
91
+ def all_less_files
92
+ all = Dir[File.join(Merb.root, source_path, "**", "*.{css,less,lss}")]
93
+ all.reject{|path| File.basename(path) =~ /^_/ }
94
+ end
95
+
96
+ private
97
+
98
+ def mtime(file)
99
+ return 0 unless File.file?(file)
100
+ File.mtime(file).to_i
101
+ end
102
+
103
+ # consider imports for mtime
104
+ # just 1 level deep so we do not get any looping/nesting errors
105
+ def mtime_including_imports(file)
106
+ mtimes = [mtime(file)]
107
+ File.readlines(file).each do |line|
108
+ if line =~ /^\s*@import ['"]([^'"]+)/
109
+ imported = File.join(File.dirname(file), $1)
110
+ mtimes << if imported =~ /\.le?ss$/ # complete path given ?
111
+ mtime(imported)
112
+ else # we need to add .less or .lss
113
+ [mtime("#{imported}.less"), mtime("#{imported}.lss")].max
114
+ end
115
+ end
116
+ end
117
+ mtimes.max
118
+ end
119
+
120
+ def compile(file)
121
+ begin
122
+ engine = File.open(file){|f| Less::Engine.new(f) }
123
+ engine.to_css
124
+ rescue Exception => e
125
+ e.message << "\nFrom #{file}"
126
+ raise e
127
+ end
128
+ end
129
+
130
+ def to_dot_css(path)
131
+ path.to_s.sub(/(le?|c)ss$/, "css")
132
+ end
133
+
134
+ def path_to_destination(path)
135
+ File.join(Merb.root, "public", destination_path, path)
136
+ end
137
+
138
+ def relative_to_source_path(path)
139
+ path.to_s.sub(File.join(Merb.root, source_path), '')[1..-1]
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,19 @@
1
+ # make sure we're running inside Merb
2
+ if defined?(Merb::Plugins)
3
+
4
+ # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
5
+ Merb::Plugins.config[:more] = {
6
+ :chickens => false
7
+ }
8
+
9
+ Merb::BootLoader.before_app_loads do
10
+ require File.join(File.dirname(__FILE__), "merb-less-more", "more.rb")
11
+ require File.join(File.dirname(__FILE__), "merb-less-more", "controller_extension.rb")
12
+ end
13
+
14
+ Merb::BootLoader.after_app_loads do
15
+ # code that can be required after the application loads
16
+ end
17
+
18
+ #Merb::Plugins.add_rakefiles "merb-less-more/merbtasks"
19
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-less-more
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Spencer Steffen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-08 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: merb-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 1
30
+ - 0
31
+ version: 1.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Merb plugin for less css support.
35
+ email: spencer@citrusme.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README
43
+ - TODO
44
+ files:
45
+ - LICENSE
46
+ - README
47
+ - Rakefile
48
+ - TODO
49
+ - lib/merb-less-more.rb
50
+ - lib/merb-less-more/controller_extension.rb
51
+ - lib/merb-less-more/more.rb
52
+ has_rdoc: true
53
+ homepage: http://citrusme.com/
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --charset=UTF-8
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.6
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Merb plugin for less css support.
82
+ test_files: []
83
+