html_ruby 我的WordPress Nginx设置

我的WordPress Nginx设置

nginx.conf
upstream phpfpm {
	server unix:/var/run/php5-fpm.sock;
}

upstream hhvm {
	server unix:/var/run/hhvm/hhvm.sock;
}

# SSL
ssl_protocols             TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers               ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
ssl_buffer_size           8k;
spdy_headers_comp         6;

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache_fpm:30m max_size=1000m;
nginx.erb
server {
	listen 80;
	<% if @use_ssl %>
	listen 443 ssl spdy;
	ssl_certificate ssl/<%= @domain %>/server.crt;
	ssl_certificate_key ssl/<%= @domain %>/server.key;
	<% end %>
	server_name <%= @domain %><% if @also_www %> www.<%= @domain %><% end %>;
	access_log  /var/log/nginx/access.log main;

	root /srv/www/<%= @path %>;
	index index.html index.htm index.php;

	include sites-available/custom/<%= @domain %>;

	location ~ \.(jpe?g|gif|png|css|bmp|js|ico)$ {
		expires 30d;
	}

	location / {
		try_files $uri $uri/ /index.php$is_args$args;
	}

	# redirect server error pages to the static page /50x.html
	#
	error_page   500 502 503 504  /50x.html;
	location = /50x.html {
		root /var/www/nginx-default;
	}

	location ~ /\.ht[a-z]+$ {
		deny all;
	}

	location ~ \.php$ {
		# Set some proxy cache stuff
		fastcgi_cache microcache_fpm;
		fastcgi_cache_key $scheme$host$request_method$request_uri;
		fastcgi_cache_valid 200 5s;
		fastcgi_cache_use_stale updating;
		fastcgi_max_temp_file_size 1M;
		fastcgi_cache_min_uses 3; # Hit a URL 3 times before caching it

		set $no_cache_set  0;
		set $no_cache_get  0;

		set $temp_caching_exemption 0;
		if ($request_method !~ ^(GET|HEAD)$) {
			set $temp_caching_exemption 1;
		}

		if ( $temp_caching_exemption = 1 ) {
			add_header Set-Cookie "_mcnc=1; Max-Age=10; Path=/";
		}

		# Bypass cache if no-cache cookie is set
		if ( $http_cookie ~* "_mcnc" ) {
			set $no_cache_set 1;
			set $no_cache_get 1;
		}

		if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
			set $no_cache_set 1;
			set $no_cache_get 1;
		}

		# fastcgi_no_cache means "Do not store this proxy response in the cache"
		fastcgi_no_cache $no_cache_set;
		# fastcgi_cache_bypass means "Do not look in the cache for this request"
		fastcgi_cache_bypass $no_cache_get;


		include        /etc/nginx/fastcgi_params;
		fastcgi_index  index.php;
		try_files      $uri =404;

		<% if @hhvm %>
		fastcgi_keep_conn on;
		fastcgi_pass hhvm;
		<% else %>
		fastcgi_pass phpfpm;
		<% end %>
	}

}

html_ruby 门面模式

门面模式

users_controller.rb
class UsersController < ApplicationController
  def index
    @facade = UserListingFacade.new(current_user)
  end
  
  private
  
  def facade
    @facade ||= ApplicationFacade.new
  end
  helper_method :facade
end
user_listing_facade.rb
class UserListingFacade
  attr_reader :user
  
  def initialize(user)
    @user = user
  end
  
  def active_users
    @active_users ||= User.published.ordered 
  end
  
  def logged_in?
    !user.nil?  
  end
end
index.html.erb
<% if facade.logged_in? %>
<ul>
  <% facade.active_users.each do |user| %>
    <li><%= user.name %></li>
  <% end %>
</ul>
<% else %>
  <p>You are not logged in!</p>
<% end %>

html_ruby Camaleon CMS自定义字段

Camaleon CMS自定义字段

post.html.erb
<h1><%= @post.the_title %></h1>
<div>
 <%= raw @post.the_content %>
</div>
<hr>
<h2>Custom fields here:</h2>
<div>
    Author name: <%= @post.get_field('author-name') %>
</div>

<div>
    Author photo:
    <%= image_tag(@post.get_field('author-photo', 'http://camaleon.tuzitio.com/media/132/slider/slide33.jpg')) %>
</div>

<div>
    Author Comments: <%= @post.the_field('author-details') %>
</div>

<h4>Photos</h4>
<ul>
    <% @post.get_fields('photos').each do |url| %>
        <li><%= image_tag(url, style: 'width: 50px; height: 50px;') %></li>
    <% end %>
</ul>

html_ruby アイコン付き提交ボタン

f.submitタグにアイコンを埋め込む

_form.html.erb
<%= button_tag, class: "btn btn-default btn-sm" do %>
  <%= content_tag :span, "送信", class: "glyphicon glyphicon-star" %>
<% end %>

html_ruby animation.html.erb

animation.html.erb
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <style type="text/css">
    body {
      user-select: none;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }

    label {
      display: block;
      width: 290px;
      height: 280px;
      position: absolute;
      z-index: 1;
      background: rgb(230, 230, 230);
      text-align: center;
    }

    #bird {
      position: absolute;
      background-image: url(./images/bird.png);
      width: 36px;
      height: 26px;
      top: 260px;
      left: 125px;
      z-index: 3;
      animation-name: jump;
      animation-duration: 2s;
      animation-iteration-count: infinite;
      animation-timing-function: linear;
      animation-play-state: paused;
    }

    @keyframes jump {
      0%   { top: 260px }
      50%  { top:   0px }
      100% { top: 260px }
    }

    #start:checked ~ #bird {
      animation-play-state: running;
    }

    #start:checked ~ #label-stop {
      z-index: 2;
    }

    #stop:checked ~ #bird {
      animation-play-state: paused;
    }

    #stop:checked ~ #label-start {
      z-index: 2;
    }
    </style>
  </head>
  <body>
    <input type="radio" name="action" id="start" />
    <input type="radio" name="action" id="stop" />

    <label for="stop" id="label-stop">&lt;for="stop" id="label-stop"&gt;</label>
    <label for="start" id="label-start">&lt;for="start" id="label-start"&gt;</label>

    <div id="bird"></div>
  </body>
</html>

html_ruby hover.html.erb

hover.html.erb
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <style type="text/css">
    button,
    button:focus
    button:active,
    button:hover {
      display: block;
      width: 10px;
      height: 10px;
      position: absolute;
      z-index: 1;
      border: none;
      border-radius: 0;
      outline : none;
      color : transparent;
      background: rgb(230, 230, 230);
    }

    #bird {
      position: absolute;
      background-image: url(./images/bird.png);
      width: 36px;
      height: 26px;
      top: 85px;
      left: 85px;
      z-index: 2;
    }

    <% 0.upto(20) do |i| %>
    <% 0.upto(20) do |j| %>
    #cell-<%= j %>-<%= i %> {
      left: <%= i * 10 %>px;
      top: <%= j * 10 %>px;
    }

    #cell-<%= j %>-<%= i %>:hover {
      background: rgb(230, 0, 0);
    }
    #cell-<%= j %>-<%= i %>:hover ~ #bird {
      transform: rotate(<%= Math::atan2((j-10)*10, (i-10)*10) * 180 / Math::PI %>deg);
    }
    <% end %>
    <% end %>
    </style>
  </head>
  <body>
    <% 0.upto(20) do |i| %>
    <% 0.upto(20) do |j| %>
    <button id="cell-<%= i %>-<%= j %>"></button>
    <% end %>
    <% end %>

    <div id="bird"></div>
  </body>
</html>

html_ruby checkboxs.html.erb

checkboxs.html.erb
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <style type="text/css">
    body {
      user-select: none;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }
    label {
      display: block;
      width: 290px;
      height: 170px;
      position: absolute;
      z-index: 1;
      background: rgba(230, 230, 230, 1);
      padding-top: 110px;
      text-align: center;
    }
    label.gameover {
      background: rgba(240, 240, 240, 1);
    }

    <% 0.upto(9) do |i| %>
    #cb-<%= i %>:checked ~ #layer-<%= i+1 %> {
      z-index: <%= i+2 %>;
    }
    <% end %>
    </style>
  </head>
  <body>
    <form>
      <% 0.upto(9) do |i| %>
      <input type="checkbox" id="cb-<%= i %>" />
      <% end %>
      <input type="reset" id="restart" />

      <label for="restart" id="layer-10" class="gameover">Game over!<br/>&lt;label for="restart" id="layer-10"&gt;</label>
      <% 9.downto(0) do |i| %>
      <label for="cb-<%= i %>" id="layer-<%= i %>">Tap here!<br/>&lt;label for="cb-<%= i %>" id="layer-<%= i %>"&gt;</label>
      <% end %>
    </form>
  </body>
</html>

html_ruby radios.html.erb

radios.html.erb
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <style type="text/css">
    body {
      user-select: none;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }

    label {
      display: block;
      width: 290px;
      height: 170px;
      position: absolute;
      z-index: 1;
      background: rgb(230, 230, 230);
      padding-top: 110px;
      text-align: center;
    }

    <% 0.upto(9) do |i| %>
    #radio-<%= i %>:checked ~ #layer-<%= i+1 %> {
      z-index: <%= i+2 %>;
    }
    <% end %>
    </style>
  </head>
  <body>
    <form>
      <% 0.upto(9) do |i| %>
      <input type="radio" name="radio" id="radio-<%= i %>" />
      <% end %>

      <% 9.downto(0) do |i| %>
      <label for="radio-<%= i %>" id="layer-<%= i %>">Tap here!<br/>&lt;label for="radio-<%= i %>" id="layer-<%= i %>"&gt;</label>
      <% end %>
    </form>
  </body>
</html>

html_ruby animation.html.erb

animation.html.erb
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
    body {
      user-select: none;
      -moz-user-select: none;
      -webkit-user-select: none;
      -ms-user-select: none;
    }

    label {
      display: block;
      width: 290px;
      height: 280px;
      position: absolute;
      z-index: 1;
      background: rgb(230, 230, 230);
      text-align: center;
    }

    #bird {
      position: absolute;
      background-image: url(./images/bird.png);
      width: 36px;
      height: 26px;
      top: 260px;
      left: 125px;
      z-index: 3;
      animation-name: jump;
      animation-duration: 2s;
      animation-iteration-count: infinite;
      animation-timing-function: linear;
      animation-play-state: paused;
    }

    @keyframes jump {
      0%   { top: 260px }
      50%  { top:   0px }
      100% { top: 260px }
    }

    #start:checked ~ #bird {
      animation-play-state: running;
    }

    #start:checked ~ #label-stop {
      z-index: 2;
    }

    #stop:checked ~ #bird {
      animation-play-state: paused;
    }

    #stop:checked ~ #label-start {
      z-index: 2;
    }
    </style>
  </head>
  <body>
    <input type="radio" name="action" id="start" />
    <input type="radio" name="action" id="stop" />

    <label for="stop" id="label-stop">&lt;for="stop" id="label-stop"&gt;</label>
    <label for="start" id="label-start">&lt;for="start" id="label-start"&gt;</label>

    <div id="bird"></div>
  </body>
</html>

html_ruby hover.html.erb

hover.html.erb
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
    a {
      display: block;
      width: 10px;
      height: 10px;
      position: absolute;
      z-index: 1;
    }

    #bird {
      position: absolute;
      background-image: url(./images/bird.png);
      width: 36px;
      height: 26px;
      top: 85px;
      left: 85px;
    }

    <% 0.upto(20) do |i| %>
    <% 0.upto(20) do |j| %>
    #cell-<%= j %>-<%= i %> {
      left: <%= i * 10 %>px;
      top: <%= j * 10 %>px;
    }

    #cell-<%= j %>-<%= i %>:hover {
      background: rgb(230, 0, 0);
    }
    #cell-<%= j %>-<%= i %>:hover ~ #bird {
      transform: rotate(<%= Math::atan2((j-10)*10, (i-10)*10) * 180 / Math::PI %>deg);
    }
    <% end %>
    <% end %>
    </style>
  </head>
  <body>
    <% 0.upto(20) do |i| %>
    <% 0.upto(20) do |j| %>
    <a id="cell-<%= i %>-<%= j %>" href="#"></a>
    <% end %>
    <% end %>

    <div id="bird"></div>
  </body>
</html>