Skip to content

Commit

Permalink
Merge branch 'master' into licensee-6
Browse files Browse the repository at this point in the history
  • Loading branch information
arfon committed Oct 21, 2015
2 parents 9d865ec + 64e7df7 commit 317219e
Show file tree
Hide file tree
Showing 35 changed files with 1,389 additions and 553 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,6 @@
[submodule "vendor/grammars/Stata.tmbundle"]
path = vendor/grammars/Stata.tmbundle
url = https://github.com/pschumm/Stata.tmbundle
[submodule "vendor/grammars/FreeMarker.tmbundle"]
path = vendor/grammars/FreeMarker.tmbundle
url = https://github.com/freemarker/FreeMarker.tmbundle
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ vendor/grammars/Docker.tmbundle:
- source.dockerfile
vendor/grammars/Elm.tmLanguage:
- source.elm
vendor/grammars/FreeMarker.tmbundle:
- text.html.ftl
vendor/grammars/G-Code/:
- source.LS
- source.MCPOST
Expand Down
73 changes: 73 additions & 0 deletions lib/linguist/blob.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'linguist/blob_helper'

module Linguist
# A Blob is a wrapper around the content of a file to make it quack
# like a Grit::Blob. It provides the basic interface: `name`,
# `data`, `path` and `size`.
class Blob
include BlobHelper

# Public: Initialize a new Blob.
#
# path - A path String (does not necessarily exists on the file system).
# content - Content of the file.
#
# Returns a FileBlob.
def initialize(path, content)
@path = path
@content = content
end

# Public: Filename
#
# Examples
#
# Blob.new("/path/to/linguist/lib/linguist.rb", "").path
# # => "/path/to/linguist/lib/linguist.rb"
#
# Returns a String
attr_reader :path

# Public: File name
#
# Returns a String
def name
File.basename(@path)
end

# Public: File contents.
#
# Returns a String.
def data
@content
end

# Public: Get byte size
#
# Returns an Integer.
def size
@content.bytesize
end

# Public: Get file extension.
#
# Returns a String.
def extension
extensions.last || ""
end

# Public: Return an array of the file extensions
#
# >> Linguist::FileBlob.new("app/views/things/index.html.erb").extensions
# => [".html.erb", ".erb"]
#
# Returns an Array
def extensions
basename, *segments = name.downcase.split(".")

segments.map.with_index do |segment, index|
"." + segments[index..-1].join(".")
end
end
end
end
45 changes: 2 additions & 43 deletions lib/linguist/file_blob.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'linguist/blob_helper'
require 'linguist/blob'

module Linguist
# A FileBlob is a wrapper around a File object to make it quack
# like a Grit::Blob. It provides the basic interface: `name`,
# `data`, `path` and `size`.
class FileBlob
class FileBlob < Blob
include BlobHelper

# Public: Initialize a new FileBlob from a path
Expand All @@ -18,34 +19,13 @@ def initialize(path, base_path = nil)
@path = base_path ? path.sub("#{base_path}/", '') : path
end

# Public: Filename
#
# Examples
#
# FileBlob.new("/path/to/linguist/lib/linguist.rb").path
# # => "/path/to/linguist/lib/linguist.rb"
#
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
# "/path/to/linguist").path
# # => "lib/linguist.rb"
#
# Returns a String
attr_reader :path

# Public: Read file permissions
#
# Returns a String like '100644'
def mode
File.stat(@fullpath).mode.to_s(8)
end

# Public: File name
#
# Returns a String
def name
File.basename(@fullpath)
end

# Public: Read file contents.
#
# Returns a String.
Expand All @@ -59,26 +39,5 @@ def data
def size
File.size(@fullpath)
end

# Public: Get file extension.
#
# Returns a String.
def extension
extensions.last || ""
end

# Public: Return an array of the file extensions
#
# >> Linguist::FileBlob.new("app/views/things/index.html.erb").extensions
# => [".html.erb", ".erb"]
#
# Returns an Array
def extensions
basename, *segments = name.downcase.split(".")

segments.map.with_index do |segment, index|
"." + segments[index..-1].join(".")
end
end
end
end
16 changes: 15 additions & 1 deletion lib/linguist/generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def generated?
generated_jni_header? ||
vcr_cassette? ||
generated_module? ||
generated_unity3d_meta?
generated_unity3d_meta? ||
generated_racc?
end

# Internal: Is the blob an Xcode file?
Expand Down Expand Up @@ -359,5 +360,18 @@ def generated_unity3d_meta?
return false unless lines.count > 1
return lines[0].include?("fileFormatVersion: ")
end

# Internal: Is this a Racc-generated file?
#
# A Racc-generated file contains:
# # This file is automatically generated by Racc x.y.z
# on the third line.
#
# Return true or false
def generated_racc?
return false unless extname == '.rb'
return false unless lines.count > 2
return lines[2].start_with?("# This file is automatically generated by Racc")
end
end
end
30 changes: 29 additions & 1 deletion lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,16 @@ Forth:
- .fs
ace_mode: forth

FreeMarker:
type: programming
color: "#0050b2"
aliases:
- ftl
extensions:
- .ftl
tm_scope: text.html.ftl
ace_mode: ftl

Frege:
type: programming
color: "#00cafe"
Expand Down Expand Up @@ -1323,6 +1333,16 @@ HTML+Django:
- htmldjango
ace_mode: django

HTML+EEX:
type: markup
tm_scope: text.html.elixir
group: HTML
aliases:
- eex
extensions:
- .eex
ace_mode: text

HTML+ERB:
type: markup
tm_scope: text.html.erb
Expand All @@ -1332,7 +1352,7 @@ HTML+ERB:
extensions:
- .erb
- .erb.deface
ace_mode: html_ruby
ace_mode: text

HTML+PHP:
type: markup
Expand Down Expand Up @@ -2063,6 +2083,14 @@ Mercury:
tm_scope: source.mercury
ace_mode: prolog

Metal:
type: programming
color: "#8f14e9"
extensions:
- .metal
tm_scope: source.c++
ace_mode: c_cpp

MiniD: # Legacy
type: programming
searchable: false
Expand Down
31 changes: 31 additions & 0 deletions samples/FreeMarker/example.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#import "layout.ftl" as layout>

<#assign results = [
{
"title": "Example Result",
"description": "Lorem ipsum dolor sit amet, pede id pellentesque, sollicitudin turpis sed in sed sed, libero dictum."
}
] />

<@layout.page title="FreeMarker Example">
<#if results?size == 0>
There were no results.
<#else>
<ul>
<#list results as result>
<li>
<strong>${result.title}</strong>
<p>${result.description}</p>
</li>
</#list>
</ul>
</#if>

<#-- This is a FreeMarker comment -->
<@currentTime />
</@layout.page>


<#macro currentTime>
${.now?string.full}
</#macro>
32 changes: 32 additions & 0 deletions samples/FreeMarker/layout.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<#ftl strip_text=true />

<#macro page title>
<!doctype html>
<html lang="${.lang}">
<head>
<title>${title}</title>
<@metaTags />
</head>
<body>
<#nested />
<@footer />
</body>
</html>
</#macro>


<#---
Default meta tags
-->
<#macro metaTags>
<#compress>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="format-detection" content="telephone=no">
</#compress>
</#macro>

<#macro footer>
<p>This page is using FreeMarker v${.version}</p>
</#macro>
26 changes: 26 additions & 0 deletions samples/HTML+EEX/index.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h1>Listing Books</h1>

<table>
<tr>
<th>Title</th>
<th>Summary</th>
<th></th>
<th></th>
<th></th>
</tr>

<%= for book <- @books do %>
<tr>
<%# comment %>
<td><%= book.title %></td>
<td><%= book.content %></td>
<td><%= link "Show", to: book_path(@conn, :show, book) %></td>
<td><%= link "Edit", to: book_path(@conn, :edit, book) %></td>
<td><%= link "Delete", to: book_path(@conn, :delete, book), method: :delete, data: [confirm: "Are you sure?"] %></td>
</tr>
<% end %>
</table>

<br />

<%= link "New book", to: book_path(@conn, :new) %>
Loading

0 comments on commit 317219e

Please sign in to comment.