simple-page-layout 0.0.2
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.
- checksums.yaml +7 -0
- data/README.md +53 -0
- data/lib/simple-page-layout.rb +71 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0859aa519b22f55fef998a0ec201d51209ab13a
|
4
|
+
data.tar.gz: 4a81bdd886b9a4cfe2959f3460375c1cdad85540
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 86a6df197aa542cdcd7f2e146ef73b9e9d9bf2657e8051d0a168c06c9b3ac55e8de36a560799f95e99ab5fe79d72ca2cb97ba17c6da14f4ad1f6eee8fbe8cd15
|
7
|
+
data.tar.gz: 58b6cfcae74a3c9946ac32de71f0c50f22e50ea7e3c828abcbbd76b8abcf9cb64a1bac11794ed82a9e2f12469dc801e033bd740c983f557fd9667ff15a0b4f7a
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# simple-page-layout
|
2
|
+
|
3
|
+
layouts made easy for rails 3
|
4
|
+
|
5
|
+
## dependencies
|
6
|
+
|
7
|
+
* haml
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
in your layout file:
|
12
|
+
|
13
|
+
```haml
|
14
|
+
-# in file views/layouts/my_layout.html.haml
|
15
|
+
|
16
|
+
!!!
|
17
|
+
- simple_page_layout :html_lang => :zh, :site_title => 'My Site' do
|
18
|
+
-# your code here with yaml
|
19
|
+
.page-content
|
20
|
+
yield
|
21
|
+
```
|
22
|
+
|
23
|
+
and then in a view of this layout:
|
24
|
+
|
25
|
+
```haml
|
26
|
+
- page_title 'page title'
|
27
|
+
|
28
|
+
.foo bar
|
29
|
+
```
|
30
|
+
|
31
|
+
you will get:
|
32
|
+
|
33
|
+
```html
|
34
|
+
<!DOCTYPE html>
|
35
|
+
<html lang='zh'>
|
36
|
+
<head>
|
37
|
+
<title>My Site | page title</title>
|
38
|
+
<meta content="authenticity_token" name="csrf-param" />
|
39
|
+
<meta content="Gf5GH0+iJtxdjZyNo+3qMV+1DqO9v8/jAHmV/Bq5Eis=" name="csrf-token" />
|
40
|
+
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
|
41
|
+
</head>
|
42
|
+
<body>
|
43
|
+
<!-- your code here -->
|
44
|
+
<div class="foo">
|
45
|
+
bar
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
|
49
|
+
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
|
50
|
+
<script src="/assets/application.js?body=1" type="text/javascript"></script>
|
51
|
+
</body>
|
52
|
+
</html>
|
53
|
+
```
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module SimplePageLayout
|
2
|
+
module Helper
|
3
|
+
class PageLayout
|
4
|
+
attr_accessor :view
|
5
|
+
attr_accessor :site_name, :html_lang
|
6
|
+
|
7
|
+
def initialize(view, site_name, options = {})
|
8
|
+
@view = view
|
9
|
+
@site_name = site_name
|
10
|
+
@html_lang = options[:html_lang]
|
11
|
+
end
|
12
|
+
|
13
|
+
def render(&block)
|
14
|
+
@view.haml_tag :html, :lang => html_lang do
|
15
|
+
render_page_layout_head
|
16
|
+
render_page_layout_body(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_page_layout_head
|
21
|
+
head_ext = @view.content_for :head
|
22
|
+
css_ext = @view.content_for :css
|
23
|
+
|
24
|
+
@view.haml_tag :head do
|
25
|
+
render_page_title
|
26
|
+
@view.haml_concat @view.csrf_meta_tags
|
27
|
+
@view.haml_concat @view.stylesheet_link_tag(:application)
|
28
|
+
@view.haml_concat head_ext if head_ext.present?
|
29
|
+
@view.haml_concat css_ext if css_ext.present?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_page_layout_body(&block)
|
34
|
+
javascript_ext = @view.content_for :javascript
|
35
|
+
|
36
|
+
@view.haml_tag :body do
|
37
|
+
yield
|
38
|
+
@view.haml_concat @view.javascript_include_tag(:application)
|
39
|
+
@view.haml_concat @view.javascript_ext if javascript_ext.present?
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_page_title
|
44
|
+
yield_title = @view.content_for :title
|
45
|
+
page_title = yield_title.blank? ? @site_name : "#{@site_name} | #{yield_title}" rescue 'SITE_NAME'
|
46
|
+
|
47
|
+
@view.haml_tag :title, page_title
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def simple_page_layout(site_name, options = {}, &block)
|
52
|
+
page_layout = PageLayout.new self, site_name, options
|
53
|
+
page_layout.render &block
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
module ExtHelper
|
58
|
+
def page_title(title)
|
59
|
+
content_for(:title) do
|
60
|
+
title
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Railtie < Rails::Railtie
|
66
|
+
initializer 'SimplePageLayout.helper' do |app|
|
67
|
+
ActionView::Base.send :include, SimplePageLayout::Helper
|
68
|
+
ActionView::Base.send :include, SimplePageLayout::ExtHelper
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-page-layout
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ben7th
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: layouts made easy for rails 3.
|
14
|
+
email: ben7th@sina.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/simple-page-layout.rb
|
20
|
+
- README.md
|
21
|
+
homepage: https://github.com/mindpin/simple-page-layout
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.0
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: simple page layout helpers
|
45
|
+
test_files: []
|