Last active
December 16, 2015 01:39
-
-
Save ashleygwilliams/5356475 to your computer and use it in GitHub Desktop.
custom sass function chooses a random(seeded) font name. want to get font name so i can include it in app head (google web font link).
files as they currently are work, but pick two different fonts :( help?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FakeApp | |
include Sass::Script::Functions | |
@@current_app = nil | |
attr_accessor :name, :dataset, :font | |
PREFIXES = ["responsive", "game", "beta", "tech", "digital", "social", "my", "our", "the", "all", "in", "on"] | |
SUFFIXES = ["box", "grid", "share", "wise", "hop", "works", "bit", "book", "list", "square", "rock", ".ly", "sy", "er", ".it", "ie", ".io", ".am", "ia", "ora", "ero", "ist", "ism", "ium", "ble", "ify", "ous", "ing"] | |
TILE_LAYERS = ["'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'OpenStreetMap'}", | |
"'http://otile{s}.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.png', {subdomains: '1234', type: 'osm', attribution: 'MapQuestOpen'}", | |
"'http://otile{s}.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.png', {subdomains: '1234', type: 'sat', attribution: 'MapQuestOpen'}", | |
'"http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png", {attribution: "OpenCycleMap"}' | |
] | |
def initialize | |
@dataset = Dataset.load_random | |
@subjects = self.dataset.json_obj["tags"] | |
@name = self.getRandomName | |
@tile_set = FakeApp.getRandomTiles | |
@@current_app = self | |
@font = getRandomFont.to_s.gsub(/ /, "+") | |
end | |
def self.current_app | |
@@current_app | |
end | |
def getRandomName | |
if rand > 0.7 | |
PREFIXES.sample + @subjects.sample | |
else | |
@subjects.sample + SUFFIXES.sample | |
end | |
end | |
def self.getRandomTiles | |
TILE_LAYERS.sample | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 5 | |
%html | |
%head | |
%title | |
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1.0"} | |
%link{:rel => 'stylesheet', :type => 'text/css', :href => "/stylesheet.css?seed=#{@seed}"} | |
%link{:rel => 'stylesheet', :type => 'text/css', :href => "http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css"} | |
%link{:href=>"http://fonts.googleapis.com/css?family=#{@app.font}", :rel=>'stylesheet', :type=>'text/css'} | |
%script{:src => "http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"} | |
%body | |
#wrap | |
.container-fluid | |
=yield | |
#push | |
%footer | |
%span © Spring 2013 | |
%script{:src => "http://code.jquery.com/jquery-1.9.1.min.js"} | |
%script{:type => "text/javascript", :src => "/js/bootstrap.js"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sass' | |
module Sass::Script::Functions | |
FONTS = ["Lobster", "Raleway","Lato","Oleo Script","Special Elite","Fredoka One"] | |
PATTERNS = ["img/bg_stripe.png", "img/bg_square.png"] | |
APP = FakeApp.current_app | |
def getRandomColor(as_str = true) | |
if as_str | |
Sass::Script::String.new("#%06x" % (rand * 0xffffff)) | |
else | |
Sass::Script::Color.new([rand(255), rand(255), rand(255)]) | |
end | |
end | |
def getRandomFont | |
font ||= '"' + FONTS.sample() + '"' | |
Sass::Script::String.new(font) | |
end | |
def getRandomPixels() | |
rpx ||= rand(40...60) | |
Sass::Script::String.new(rpx.to_s + "px") | |
end | |
def getRandomPattern | |
pattern ||= PATTERNS.sample() | |
Sass::Script::String.new(pattern) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment