You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ts...@apache.org on 2015/05/30 07:03:36 UTC

[10/26] drill git commit: Body class plugin for fun

Body class plugin for fun


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/f2414032
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/f2414032
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/f2414032

Branch: refs/heads/gh-pages
Commit: f24140322a8a901532e91e03ba93ab7ee3980c6d
Parents: cc1c444
Author: Elliot Berry <el...@Marks-iMac-2.local>
Authored: Fri May 29 11:29:27 2015 -0400
Committer: Elliot Berry <el...@Marks-iMac-2.local>
Committed: Fri May 29 11:29:27 2015 -0400

----------------------------------------------------------------------
 _layouts/default.html |  2 +-
 _plugins/bodyClass.rb | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/f2414032/_layouts/default.html
----------------------------------------------------------------------
diff --git a/_layouts/default.html b/_layouts/default.html
index ccb47db..4059872 100644
--- a/_layouts/default.html
+++ b/_layouts/default.html
@@ -3,7 +3,7 @@
 
 {% include head.html %}
 
-<body onResize="resized();">
+<body onResize="resized();" class="{% body_class %}">
   <div class="page-wrap">
     {% include menu.html %}
     {{ content }}

http://git-wip-us.apache.org/repos/asf/drill/blob/f2414032/_plugins/bodyClass.rb
----------------------------------------------------------------------
diff --git a/_plugins/bodyClass.rb b/_plugins/bodyClass.rb
new file mode 100644
index 0000000..876121f
--- /dev/null
+++ b/_plugins/bodyClass.rb
@@ -0,0 +1,34 @@
+class BodyClassTag < Liquid::Tag  
+
+  def generate_body_class(prefix, id)
+    id = id.gsub(/\.\w*?$/, '').gsub(/[-\/]/, '_').gsub(/^_/, '') # Remove extension from url, replace '-' and '/' with underscore, Remove leading '_'
+
+    case prefix
+    when "class"
+      prefix = ""
+    else
+      prefix = "#{prefix}_"
+    end
+
+    "#{prefix}#{id}"
+  end
+
+  def render(context)
+    page = context.environments.first["page"]
+    classes = []
+
+    %w[class url categories tags layout].each do |prop|
+      next unless page.has_key?(prop)
+      if page[prop].kind_of?(Array)
+        page[prop].each { |proper| classes.push generate_body_class(prop, proper) }
+      else
+        classes.push generate_body_class(prop, page[prop])
+      end
+    end
+
+    classes.join(" ")
+  end
+
+end
+
+Liquid::Template.register_tag('body_class', BodyClassTag)
\ No newline at end of file