fancyviews 1.3 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.markdown +49 -0
- data/Rakefile +23 -4
- data/VERSION +1 -0
- data/examples.rb +78 -0
- data/fancyviews.gemspec +59 -17
- data/lib/sinatra/fancyviews.rb +6 -3
- metadata +52 -15
data/.gitignore
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Fancyviews
|
2
|
+
==========
|
3
|
+
|
4
|
+
Fancyviews is a sinatra plugin for developers already using haml and sass.
|
5
|
+
|
6
|
+
The problem with the view layer of most codebases: adding code is quick and easy but removing that same code two weeks later is fraught with peril.
|
7
|
+
|
8
|
+
This asymmetry is the unfortunate result of organizing view code by _type_ instead of _use_. The HTML/DOM code goes in one bucket and the styles & javascript get their own buckets. When the time comes to make a change that requires modification to all three types of view code, the specific lines must be located in each bucket.
|
9
|
+
|
10
|
+
Fancyviews flips this around and allows you to organize your view code by _use_ but renders it to the browser as if it was organized by type. You put all the code in one view file, nesting your javascript and sass beneath the `script` and `style` haml filters:
|
11
|
+
|
12
|
+
# fancy.haml
|
13
|
+
:style
|
14
|
+
#fancy
|
15
|
+
:font-family Helvetica
|
16
|
+
:font-size 200px
|
17
|
+
:font-weight bold
|
18
|
+
:color black
|
19
|
+
:margin 0
|
20
|
+
:padding 10px
|
21
|
+
:letter-spacing -4px
|
22
|
+
|
23
|
+
:script
|
24
|
+
document.getElementById('fancy').onclick = function() { alert('Fancy click') }
|
25
|
+
|
26
|
+
%h1#fancy Oooh! Fancy
|
27
|
+
|
28
|
+
And now you use the `view` method wherever you want include this:
|
29
|
+
|
30
|
+
# anywhere.haml
|
31
|
+
// ... some other code
|
32
|
+
view :fancy
|
33
|
+
// ... more codez
|
34
|
+
|
35
|
+
The haml will be rendered and included, just like normal partial rendering, but the styles and scripts will be captured by fancy goats. Then somewhere in your layout you steal them back from those sneaky goats with the `styles` and `scripts` (note the plurals) methods:
|
36
|
+
|
37
|
+
# layout.haml
|
38
|
+
%head
|
39
|
+
= styles
|
40
|
+
%body
|
41
|
+
...
|
42
|
+
= scripts
|
43
|
+
|
44
|
+
For syntax highlighting in textmate, use this haml bundle: http://github.com/quackingduck/ruby-haml.tmbundle/tree/master and for sass use this one:
|
45
|
+
http://github.com/quackingduck/ruby-sass-tmbundle/tree/master
|
46
|
+
|
47
|
+
The `style` method can also import other sass files present in the views directory:
|
48
|
+
|
49
|
+
= styles(:import => :base)
|
data/Rakefile
CHANGED
@@ -8,9 +8,28 @@ task :default => :test
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
task :examples do
|
12
|
+
ruby 'examples.rb'
|
13
|
+
end
|
14
|
+
|
11
15
|
begin
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |s|
|
18
|
+
s.name = "fancyviews"
|
19
|
+
s.homepage = "http://github.com/quackingduck/fancyviews"
|
20
|
+
s.summary = "A views module for sinatra"
|
21
|
+
s.email = "myles@myles.id.au"
|
22
|
+
s.authors = ["Myles Byrne"]
|
23
|
+
s.has_rdoc = false
|
24
|
+
|
25
|
+
s.add_dependency "sinatra", ">= 0.9.1.1"
|
26
|
+
s.add_dependency "haml", ">= 2.2"
|
27
|
+
|
28
|
+
s.add_development_dependency "exemplor", ">= 2000.0.0"
|
29
|
+
s.add_development_dependency "fancypath", ">= 0.5.13"
|
30
|
+
s.add_development_dependency "rack-test", ">= 0.4.0"
|
31
|
+
end
|
32
|
+
Jeweler::GemcutterTasks.new
|
15
33
|
rescue LoadError
|
16
|
-
|
34
|
+
puts "Install jeweler to build gem"
|
35
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.4.0
|
data/examples.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'exemplor'
|
2
|
+
require 'fancypath'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
# http://gist.github.com/58009
|
6
|
+
def Clip(str)
|
7
|
+
return str unless str.include?("\n")
|
8
|
+
first_indent = str.match(/\n\s*/).to_s
|
9
|
+
str.gsub( first_indent, "\n" ).strip
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestApp
|
13
|
+
|
14
|
+
attr_reader :path
|
15
|
+
|
16
|
+
def initialize(path)
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def views_path; path.join('views').create end
|
21
|
+
|
22
|
+
def view(name, src)
|
23
|
+
views_path.join(name).write Clip(src)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_body
|
27
|
+
require 'shellwords'
|
28
|
+
# rack test prints errors to stderr twice ... not sure why
|
29
|
+
test = Clip %{
|
30
|
+
require 'app'
|
31
|
+
set :environment, :test
|
32
|
+
|
33
|
+
require 'rack/test'
|
34
|
+
puts Rack::Test::Session.new(Rack::MockSession.new(Sinatra::Application)).get('/test').body
|
35
|
+
}
|
36
|
+
|
37
|
+
`ruby -I#{path} -e #{test.split("\n").join(";").shellescape}`
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
eg.helpers do
|
43
|
+
|
44
|
+
def create_app(app_src)
|
45
|
+
app = TestApp.new Fancypath(__FILE__).dir.join('example_app')
|
46
|
+
app.path.join('app.rb').write Clip(app_src)
|
47
|
+
app
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
eg "multiple libraries can be imported with #styles()" do
|
53
|
+
app = create_app %{
|
54
|
+
require 'sinatra'
|
55
|
+
require File.dirname(__FILE__) + '/../lib/sinatra/fancyviews'
|
56
|
+
|
57
|
+
get('/test') { page :test }
|
58
|
+
}
|
59
|
+
app.view 'lib1.sass', %{
|
60
|
+
=red
|
61
|
+
:background red
|
62
|
+
}
|
63
|
+
app.view 'lib2.sass', %{
|
64
|
+
=blue
|
65
|
+
:background blue
|
66
|
+
}
|
67
|
+
app.view 'test.haml', %{
|
68
|
+
:style
|
69
|
+
.red
|
70
|
+
+red
|
71
|
+
.blue
|
72
|
+
+blue
|
73
|
+
}
|
74
|
+
app.view 'layout.haml', %{
|
75
|
+
= styles :import => %w(lib1 lib2)
|
76
|
+
}
|
77
|
+
app.test_body
|
78
|
+
end
|
data/fancyviews.gemspec
CHANGED
@@ -1,20 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
1
6
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.
|
7
|
-
s.
|
8
|
-
s.
|
9
|
-
s.
|
7
|
+
s.name = %q{fancyviews}
|
8
|
+
s.version = "1.4.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Myles Byrne"]
|
12
|
+
s.date = %q{2009-11-11}
|
13
|
+
s.email = %q{myles@myles.id.au}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"README.markdown"
|
16
|
+
]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"examples.rb",
|
23
|
+
"fancyviews.gemspec",
|
24
|
+
"lib/sinatra/fancyviews.rb",
|
25
|
+
"test/html4.rb",
|
26
|
+
"test/html5.rb"
|
27
|
+
]
|
28
|
+
s.homepage = %q{http://github.com/quackingduck/fancyviews}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
10
30
|
s.require_paths = ["lib"]
|
11
|
-
s.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
test/
|
16
|
-
|
17
|
-
|
18
|
-
s.
|
19
|
-
|
31
|
+
s.rubygems_version = %q{1.3.5}
|
32
|
+
s.summary = %q{A views module for sinatra}
|
33
|
+
s.test_files = [
|
34
|
+
"test/html4.rb",
|
35
|
+
"test/html5.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 3
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.1.1"])
|
44
|
+
s.add_runtime_dependency(%q<haml>, [">= 2.2"])
|
45
|
+
s.add_development_dependency(%q<exemplor>, [">= 2000.0.0"])
|
46
|
+
s.add_development_dependency(%q<fancypath>, [">= 0.5.13"])
|
47
|
+
s.add_development_dependency(%q<rack-test>, [">= 0.4.0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.1.1"])
|
50
|
+
s.add_dependency(%q<haml>, [">= 2.2"])
|
51
|
+
s.add_dependency(%q<exemplor>, [">= 2000.0.0"])
|
52
|
+
s.add_dependency(%q<fancypath>, [">= 0.5.13"])
|
53
|
+
s.add_dependency(%q<rack-test>, [">= 0.4.0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<sinatra>, [">= 0.9.1.1"])
|
57
|
+
s.add_dependency(%q<haml>, [">= 2.2"])
|
58
|
+
s.add_dependency(%q<exemplor>, [">= 2000.0.0"])
|
59
|
+
s.add_dependency(%q<fancypath>, [">= 0.5.13"])
|
60
|
+
s.add_dependency(%q<rack-test>, [">= 0.4.0"])
|
61
|
+
end
|
20
62
|
end
|
data/lib/sinatra/fancyviews.rb
CHANGED
@@ -70,12 +70,15 @@ module Sinatra
|
|
70
70
|
|
71
71
|
# renders all the styles captured by the :style filter
|
72
72
|
def styles(options = {})
|
73
|
-
imported = options
|
74
|
-
File.read("#{self.options.views}/#{
|
73
|
+
imported = if options[:import]
|
74
|
+
[*options[:import]].map { |name| File.read("#{self.options.views}/#{name}.sass") }.join("\n")
|
75
|
+
end
|
75
76
|
|
76
77
|
rendered_styles = fancyviews.included_styles.map do |name, sass|
|
77
78
|
# would be nice if construction took an :offest to go along with the :filename
|
78
|
-
eng = Sass::Engine.new(imported + "\n" + sass,
|
79
|
+
eng = Sass::Engine.new((imported || '') + "\n" + sass,
|
80
|
+
:attribute_syntax => :normal,
|
81
|
+
:load_paths => [self.options.views])
|
79
82
|
"\n/* -- #{name} -- */\n" + eng.render
|
80
83
|
end.join
|
81
84
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fancyviews
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myles Byrne
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-11 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,25 +32,61 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "2.2"
|
34
34
|
version:
|
35
|
-
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: exemplor
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2000.0.0
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: fancypath
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.5.13
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
type: :development
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 0.4.0
|
64
|
+
version:
|
65
|
+
description:
|
36
66
|
email: myles@myles.id.au
|
37
67
|
executables: []
|
38
68
|
|
39
69
|
extensions: []
|
40
70
|
|
41
|
-
extra_rdoc_files:
|
42
|
-
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.markdown
|
43
73
|
files:
|
74
|
+
- .gitignore
|
75
|
+
- README.markdown
|
44
76
|
- Rakefile
|
77
|
+
- VERSION
|
78
|
+
- examples.rb
|
45
79
|
- fancyviews.gemspec
|
46
80
|
- lib/sinatra/fancyviews.rb
|
47
81
|
- test/html4.rb
|
48
82
|
- test/html5.rb
|
49
|
-
has_rdoc:
|
50
|
-
homepage:
|
51
|
-
|
52
|
-
rdoc_options: []
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/quackingduck/fancyviews
|
85
|
+
licenses: []
|
53
86
|
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --charset=UTF-8
|
54
90
|
require_paths:
|
55
91
|
- lib
|
56
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -67,10 +103,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
103
|
version:
|
68
104
|
requirements: []
|
69
105
|
|
70
|
-
rubyforge_project:
|
71
|
-
rubygems_version: 1.3.
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.3.5
|
72
108
|
signing_key:
|
73
|
-
specification_version:
|
74
|
-
summary:
|
75
|
-
test_files:
|
76
|
-
|
109
|
+
specification_version: 3
|
110
|
+
summary: A views module for sinatra
|
111
|
+
test_files:
|
112
|
+
- test/html4.rb
|
113
|
+
- test/html5.rb
|