effigy 0.3.0 → 0.3.1
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.
- data/Rakefile +21 -2
- data/VERSION +1 -1
- data/generators/effigy_view/effigy_view_generator.rb +81 -0
- data/generators/effigy_view/templates/layout_template.erb +7 -0
- data/generators/effigy_view/templates/layout_view.erb +13 -0
- data/generators/effigy_view/templates/template.erb +3 -0
- data/generators/effigy_view/templates/view.erb +12 -0
- data/rails/init.rb +1 -0
- data/spec/rails/generators/effigy_view_spec.rb +2 -2
- metadata +8 -2
data/Rakefile
CHANGED
@@ -5,6 +5,22 @@ require 'rake/gempackagetask'
|
|
5
5
|
desc 'Default: run the specs and metrics.'
|
6
6
|
task :default => [:spec, :metrics]
|
7
7
|
|
8
|
+
task :rails_root do
|
9
|
+
rails_root = File.join('tmp', 'rails_root')
|
10
|
+
unless File.exist?(rails_root)
|
11
|
+
FileUtils.mkdir_p(File.dirname(rails_root))
|
12
|
+
command = "rails #{rails_root}"
|
13
|
+
output = `#{command} 2>&1`
|
14
|
+
if $? == 0
|
15
|
+
FileUtils.ln_s(FileUtils.pwd, File.join(rails_root, 'vendor', 'plugins'))
|
16
|
+
else
|
17
|
+
$stderr.puts "Command failed with status #{$?}:"
|
18
|
+
$stderr.puts command
|
19
|
+
$stderr.puts output
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
8
24
|
begin
|
9
25
|
require 'spec/rake/spectask'
|
10
26
|
|
@@ -33,11 +49,14 @@ begin
|
|
33
49
|
require 'jeweler'
|
34
50
|
Jeweler::Tasks.new do |gem|
|
35
51
|
gem.name = %q{effigy}
|
36
|
-
gem.version = "0.1"
|
37
52
|
gem.summary = %q{Effigy provides a view and template framework without a templating language.}
|
38
53
|
gem.description = %q{Define views in Ruby and templates in HTML. Avoid code interpolation or ugly templating languages. Use ids, class names, and semantic structures already present in your documents to produce content.}
|
39
54
|
|
40
|
-
gem.files = FileList['[A-Z]*',
|
55
|
+
gem.files = FileList['[A-Z]*',
|
56
|
+
'lib/**/*.rb',
|
57
|
+
'spec/**/*.rb',
|
58
|
+
'rails/**/*.rb',
|
59
|
+
'generators/**/*.*']
|
41
60
|
gem.require_path = 'lib'
|
42
61
|
gem.test_files = Dir[*['spec/**/*_spec.rb']]
|
43
62
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class EffigyViewGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |manifest|
|
5
|
+
manifest.effigy_directories
|
6
|
+
manifest.effigy_views view_names
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def controller_path
|
13
|
+
File.join(class_path, file_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def view_names
|
17
|
+
actions
|
18
|
+
end
|
19
|
+
|
20
|
+
def record
|
21
|
+
EffigyViewManifest.new(self, controller_path) { |manifest| yield manifest }
|
22
|
+
end
|
23
|
+
|
24
|
+
class EffigyViewManifest < Rails::Generator::Manifest
|
25
|
+
def initialize(generator, controller_path)
|
26
|
+
@controller_path = controller_path
|
27
|
+
super(generator)
|
28
|
+
end
|
29
|
+
|
30
|
+
def effigy_directories
|
31
|
+
directory File.join('app', 'views', @controller_path)
|
32
|
+
directory File.join('app', 'templates', @controller_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def effigy_views(view_names)
|
36
|
+
view_names.each do |view_name|
|
37
|
+
effigy_view view_name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def effigy_view(view_name)
|
42
|
+
view_path = File.join('app', 'views', @controller_path, "#{view_name}.html.effigy")
|
43
|
+
template_path = File.join('app', 'templates', @controller_path, "#{view_name}.html")
|
44
|
+
assigns = { :view_class_name => view_class_name(view_name),
|
45
|
+
:template_path => template_path,
|
46
|
+
:view_path => view_path }
|
47
|
+
|
48
|
+
template template_for('view'),
|
49
|
+
view_path,
|
50
|
+
:assigns => assigns
|
51
|
+
|
52
|
+
template template_for('template'),
|
53
|
+
template_path,
|
54
|
+
:assigns => assigns
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def view_class_name(view_name)
|
60
|
+
prefix = "#{@controller_path.camelize}#{view_name.camelize}"
|
61
|
+
if layout?
|
62
|
+
"#{prefix}Layout".sub(/^::Layouts(::)?/, '')
|
63
|
+
else
|
64
|
+
"#{prefix}View".sub(/^::/, '')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def template_for(file)
|
69
|
+
if layout?
|
70
|
+
"layout_#{file}.erb"
|
71
|
+
else
|
72
|
+
"#{file}.erb"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def layout?
|
77
|
+
@controller_path =~ /^\/layouts/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= view_class_name %> < Effigy::Rails::View
|
2
|
+
private
|
3
|
+
def transform
|
4
|
+
# Apply transformations to the template file here:
|
5
|
+
# text('h1', 'Hello')
|
6
|
+
# Assigns from the action are available:
|
7
|
+
# text('h1', @post.title)
|
8
|
+
# Transformations will be applied to to the template file:
|
9
|
+
# <%= template_path %>
|
10
|
+
# See the documentation for more information.
|
11
|
+
html('body', content_for(:layout))
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= view_class_name %> < Effigy::Rails::View
|
2
|
+
private
|
3
|
+
def transform
|
4
|
+
# Apply transformations to the template file here:
|
5
|
+
# text('h1', 'Hello')
|
6
|
+
# Assigns from the action are available:
|
7
|
+
# text('h1', @post.title)
|
8
|
+
# Transformations will be applied to to the template file:
|
9
|
+
# <%= template_path %>
|
10
|
+
# See the documentation for more information.
|
11
|
+
end
|
12
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'effigy/rails'
|
@@ -46,7 +46,7 @@ describe "script/generate effigy_view users create" do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should create a view file" do
|
49
|
-
view_path.should contain("class #{@view_class_name} < Rails::
|
49
|
+
view_path.should contain("class #{@view_class_name} < Effigy::Rails::View")
|
50
50
|
view_path.should contain("private")
|
51
51
|
view_path.should contain("def transform")
|
52
52
|
view_path.should contain(relative_template_path)
|
@@ -93,7 +93,7 @@ describe "script/generate effigy_view layouts narrow" do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should create a view file" do
|
96
|
-
view_path.should contain("class #{@layout_class_name} < Rails::
|
96
|
+
view_path.should contain("class #{@layout_class_name} < Effigy::Rails::View")
|
97
97
|
view_path.should contain("private")
|
98
98
|
view_path.should contain("def transform")
|
99
99
|
view_path.should contain("html('body', content_for(:layout))")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effigy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Ferris
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-02 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,6 +37,11 @@ files:
|
|
37
37
|
- Rakefile
|
38
38
|
- TODO.textile
|
39
39
|
- VERSION
|
40
|
+
- generators/effigy_view/effigy_view_generator.rb
|
41
|
+
- generators/effigy_view/templates/layout_template.erb
|
42
|
+
- generators/effigy_view/templates/layout_view.erb
|
43
|
+
- generators/effigy_view/templates/template.erb
|
44
|
+
- generators/effigy_view/templates/view.erb
|
40
45
|
- lib/effigy.rb
|
41
46
|
- lib/effigy/class_list.rb
|
42
47
|
- lib/effigy/core_ext/hash.rb
|
@@ -47,6 +52,7 @@ files:
|
|
47
52
|
- lib/effigy/rails/view.rb
|
48
53
|
- lib/effigy/selection.rb
|
49
54
|
- lib/effigy/view.rb
|
55
|
+
- rails/init.rb
|
50
56
|
- spec/effigy/class_list_spec.rb
|
51
57
|
- spec/effigy/core_ext/hash_spec.rb
|
52
58
|
- spec/effigy/core_ext/object_spec.rb
|