#= require es6shim #= require react #= require underscore #= require underscore.string global.Rev = class Revelry @App: Mixins: {} Components: {} Examples: {} @appObject: (name, object) -> @registerObject "App.#{name}", object @registerObject: (name, object) -> parts = name.split('.') container = this for part, i in parts if i == parts.length - 1 if container[part]? && name != "App.Components.Main" console.warn "Object previously defined: #{name}" container[part] = object else container[part] ||= {} container = container[part] object @appComponent: (name, object) -> name = "App.Components.#{name}" @registerObject name, @createReactClass(name, object) @registerComponent: (name, object) -> name = "Components.#{name}" @registerObject name, @createReactClass("Rev.#{name}", object) @createReactClass: (displayName, object) -> object.displayName = displayName object.mixins ||= [] for mixin in object.mixins console.warn "Attempted to include missing mixin." unless mixin? object.mixins.unshift @Mixins.Core if typeof object == 'function' # ES6 or Coffeescript class, OK as-is object else # Old style react class - pass to createClass React.createClass object @appMixin: (name, object) -> throw "Missing mixin `#{name}`" unless object? @registerObject "App.Mixins.#{name}", object @registerMixin: (name, object) -> throw "Missing mixin `#{name}`" unless object? @registerObject "Mixins.#{name}", object @registerExample: (name, object) -> name = "Examples.#{name}" @registerObject name, @createReactClass("Rev.#{name}", object) @appExample: (name, object) -> name = "App.Examples.#{name}" @registerObject name, @createReactClass(name, object) @registerModel: (name, object) -> @registerObject "Models.#{name}", object @appModel: (name, object) -> @registerObject "App.Models.#{name}", object @pullInto: (context) -> () => context[componentName] = Rev.Components[componentName] for i, componentName of arguments @ESCAPE_LOOKUP: "&": "&" ">": ">" "<": "<" "\"": """ "'": "'" @ESCAPE_REGEX: /[&><"']/g @_escaper: (match) => @ESCAPE_LOOKUP[match] @escapeTextForBrowser: (text) => ('' + text).replace(@ESCAPE_REGEX, @_escaper) @_resetUniqueId = () -> idCounter = 0 _.uniqueId = (prefix) -> id = ++idCounter + '' if prefix then prefix + id else id @hasView: (path) -> @Components.Main.hasView path @viewToString: (path, options) -> @_resetUniqueId() props = path: path options: JSON.parse(options) json = @escapeTextForBrowser(JSON.stringify props) tag = (inner) -> "
#{inner}
" # 2 checks: One is for standard Rails apps and one for jsonapi-resources. return tag '' if props.options.disable_prerender or props.options.meta?['disable-prerender'] try if React.renderComponentToString? # < 0.13 tag React.renderComponentToString(@App.Components.Main(props)) else # >= 0.13 tag React.renderToString(React.createElement(@App.Components.Main, props)) catch e "
#{path}
" + "
"+"#{@escapeTextForBrowser e.stack}"+"
" + tag("") + "
#{json}
" @initExecjsRails: -> global.execjs_rails_has_view = @hasView.bind(this) global.execjs_rails_handler = @viewToString.bind(this) global.App = Rev.App