{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/58352326","id":58352326,"diff_hunk":"@@ -105,97 +186,375 @@ def datasource(options)\n           stat_tag: @visualization.id\n         }\n \n-        ds[:template_name] = CartoDB::NamedMapsWrapper::NamedMap.template_name(@visualization.id) if @visualization.retrieve_named_map?\n+        if @visualization.retrieve_named_map?\n+          ds[:template_name] = CartoDB::NamedMapsWrapper::NamedMap.template_name(@visualization.id)\n+        end\n \n         ds\n       end\n \n-      def user_vizjson_info\n+      def user_info_vizjson(user)\n         {\n           fullname: user.name.present? ? user.name : user.username,\n           avatar_url: user.avatar_url\n         }\n       end\n \n-      # WIP #6953: remove next methods patch v2 vizjson #####################################\n+      def widgets_vizjson\n+        Carto::Widget.from_visualization_id(@visualization.id).map do |widgets|\n+          Carto::Api::WidgetPresenter.new(widgets).to_vizjson\n+        end\n+      end\n+\n+      def html_safe(string)\n+        if string.present?\n+          renderer = Redcarpet::Render::Safe\n+          markdown = Redcarpet::Markdown.new(renderer, {})\n+          markdown.render string\n+        end\n+      end\n+    end\n \n-      def symbolize_vizjson(vizjson)\n-        vizjson = vizjson.deep_symbolize_keys\n-        vizjson[:layers] = vizjson[:layers].map(&:deep_symbolize_keys)\n-        vizjson\n+    class VizJSON3NamedMapPresenter\n+      NAMED_MAP_TYPE = 'namedmap'.freeze\n+      LAYER_TYPES_TO_DECORATE = ['torque'].freeze\n+      DEFAULT_TILER_FILTER = 'mapnik'.freeze\n+\n+      # @throws NamedMapsPresenterError\n+      def initialize(visualization, layergroup, options, configuration)\n+        @visualization    = visualization\n+        @options          = options\n+        @configuration    = configuration\n+        @layergroup_data  = layergroup\n+        @named_map_name   = CartoDB::NamedMapsWrapper::NamedMap.template_name(@visualization.id)\n       end\n \n-      def layer_vizjson2_to_3(layer_data)\n-        if layer_data[:type] == 'torque'\n-          torque_layer_vizjson2_to_3(layer_data)\n+      # Prepare a PORO (Hash object) for easy JSONification\n+      # @see https://github.com/CartoDB/cartodb.js/blob/privacy-maps/doc/vizjson_format.md\n+      # @throws NamedMapsPresenterError\n+      def to_vizjson\n+        if @visualization.data_layers.empty?\n+          nil # When there are no layers don't return named map data\n+        else\n+          api_templates_type = @options.fetch(:https_request, false) ? 'private' : 'public'\n+          privacy_type = @visualization.password_protected? ? 'private' : api_templates_type\n+\n+          {\n+            type:     NAMED_MAP_TYPE,\n+            order:    1,\n+            options:  {\n+              type:             NAMED_MAP_TYPE,\n+              user_name:        @options.fetch(:user_name),\n+              maps_api_template: ApplicationHelper.maps_api_template(privacy_type),\n+              sql_api_template: ApplicationHelper.sql_api_template(privacy_type),\n+              filter:           @configuration[:tiler].fetch('filter', DEFAULT_TILER_FILTER),","path":"app/controllers/carto/api/vizjson3_presenter.rb","position":320,"original_position":320,"commit_id":"dfab4cf6e4d8952cc6d19dd5647a0893cc5495ad","original_commit_id":"dfab4cf6e4d8952cc6d19dd5647a0893cc5495ad","user":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"body":"Ugly indeed. I'll remove the alignment.","created_at":"2016-04-04T09:55:11Z","updated_at":"2016-04-04T09:55:11Z","html_url":"https://github.com/CartoDB/cartodb/pull/7017#discussion_r58352326","pull_request_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments/58352326"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/7017#discussion_r58352326"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017","id":64926376,"html_url":"https://github.com/CartoDB/cartodb/pull/7017","diff_url":"https://github.com/CartoDB/cartodb/pull/7017.diff","patch_url":"https://github.com/CartoDB/cartodb/pull/7017.patch","issue_url":"https://api.github.com/repos/CartoDB/cartodb/issues/7017","number":7017,"state":"open","locked":false,"title":"6953 vizjson 3 generation 2","user":{"login":"juanignaciosl","id":932968,"avatar_url":"https://avatars.githubusercontent.com/u/932968?v=3","gravatar_id":"","url":"https://api.github.com/users/juanignaciosl","html_url":"https://github.com/juanignaciosl","followers_url":"https://api.github.com/users/juanignaciosl/followers","following_url":"https://api.github.com/users/juanignaciosl/following{/other_user}","gists_url":"https://api.github.com/users/juanignaciosl/gists{/gist_id}","starred_url":"https://api.github.com/users/juanignaciosl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juanignaciosl/subscriptions","organizations_url":"https://api.github.com/users/juanignaciosl/orgs","repos_url":"https://api.github.com/users/juanignaciosl/repos","events_url":"https://api.github.com/users/juanignaciosl/events{/privacy}","received_events_url":"https://api.github.com/users/juanignaciosl/received_events","type":"User","site_admin":false},"body":"Until now VizJSON 3 was a colllection of patches on v2. These changes make VizJSON v3 100% independent and based on ActiveRecord models only.","created_at":"2016-04-01T10:42:43Z","updated_at":"2016-04-04T09:55:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07325196cf54d2241054bb567ebc4ef8098611bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017/commits","review_comments_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017/comments","review_comment_url":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/issues/7017/comments","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/dfab4cf6e4d8952cc6d19dd5647a0893cc5495ad","head":{"label":"CartoDB:6953-Vizjson_3_generation_2","ref":"6953-Vizjson_3_generation_2","sha":"dfab4cf6e4d8952cc6d19dd5647a0893cc5495ad","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-04-03T09:21:34Z","pushed_at":"2016-04-04T09:52:39Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":380353,"stargazers_count":1097,"watchers_count":1097,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":273,"mirror_url":null,"open_issues_count":861,"forks":273,"open_issues":861,"watchers":1097,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"a64039b571a317cf2fa644e0a9a867ec4d665288","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":4909355,"name":"cartodb","full_name":"CartoDB/cartodb","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/cartodb","description":"Location Intelligence & Data Visualization tool","fork":false,"url":"https://api.github.com/repos/CartoDB/cartodb","forks_url":"https://api.github.com/repos/CartoDB/cartodb/forks","keys_url":"https://api.github.com/repos/CartoDB/cartodb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/cartodb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/cartodb/teams","hooks_url":"https://api.github.com/repos/CartoDB/cartodb/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/cartodb/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/cartodb/events","assignees_url":"https://api.github.com/repos/CartoDB/cartodb/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/cartodb/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/cartodb/tags","blobs_url":"https://api.github.com/repos/CartoDB/cartodb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/cartodb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/cartodb/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/cartodb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/cartodb/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/cartodb/languages","stargazers_url":"https://api.github.com/repos/CartoDB/cartodb/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/cartodb/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/cartodb/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/cartodb/subscription","commits_url":"https://api.github.com/repos/CartoDB/cartodb/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/cartodb/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/cartodb/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/cartodb/issues/comments{/number}","contents_url":"https://api.github.com/repos/CartoDB/cartodb/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/cartodb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/cartodb/merges","archive_url":"https://api.github.com/repos/CartoDB/cartodb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/cartodb/downloads","issues_url":"https://api.github.com/repos/CartoDB/cartodb/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/cartodb/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/cartodb/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/cartodb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/cartodb/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/cartodb/releases{/id}","deployments_url":"https://api.github.com/repos/CartoDB/cartodb/deployments","created_at":"2012-07-05T15:23:45Z","updated_at":"2016-04-03T09:21:34Z","pushed_at":"2016-04-04T09:52:39Z","git_url":"git://github.com/CartoDB/cartodb.git","ssh_url":"git@github.com:CartoDB/cartodb.git","clone_url":"https://github.com/CartoDB/cartodb.git","svn_url":"https://github.com/CartoDB/cartodb","homepage":"http://cartodb.com","size":380353,"stargazers_count":1097,"watchers_count":1097,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":273,"mirror_url":null,"open_issues_count":861,"forks":273,"open_issues":861,"watchers":1097,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017"},"html":{"href":"https://github.com/CartoDB/cartodb/pull/7017"},"issue":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/7017"},"comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/issues/7017/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/cartodb/pulls/7017/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/cartodb/statuses/dfab4cf6e4d8952cc6d19dd5647a0893cc5495ad"}}}}